-
-
Notifications
You must be signed in to change notification settings - Fork 929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: force passed locales into faker constructor #580
Conversation
I think it fails, because you don't provide any locales. Maybe we need to change the type on your side to force to provide a |
Uhm... tests are green? 👀 |
Codecov Report
@@ Coverage Diff @@
## main #580 +/- ##
=======================================
Coverage 99.34% 99.34%
=======================================
Files 1923 1923
Lines 176891 176903 +12
Branches 896 901 +5
=======================================
+ Hits 175735 175748 +13
+ Misses 1100 1099 -1
Partials 56 56
|
I assume since it probably returns See also: #581 |
The tests are green just because I defined them with I see what you mean now about not providing any locales, i.e. I need replicate something like this: import { Faker } from '../faker';
import sv from '../locales/sv';
import en from '../locales/en';
const faker = new Faker({
locale: 'sv',
localeFallback: 'en',
locales: {
sv,
en,
},
});
export = faker; But I haven't found any way to actually import the locale data externally. I think the |
Yes, that would make it more obvious for anyone looking at the tests.
Yes, currently there isn't because it wasn't in 5.x. This is planned for a release after 6.0 when we actually start adding fixes and features. |
Done.
Ah, okay. I wonder if the Faker class shouldn't be exported from the package in 6.0 then, if the locale data it needs won't be? I tried to use the class because I got it as a code completion via the TypeScript Language Server in VSCode. Not sure if there's anything useful to make out of the tests in this PR then. I guess making the locales field required in the constructor would help like @Shinigami92 said, and/or a better error message when locale data is missing. |
Could you adjust the constructor to not have a default and require the locales? |
@vith Would you like to open a new PR to do this or maybe just use this PR? |
I recommend using this one, as both parts fix+test belong together anyway. |
I will jump into this PR now and fix the constructor |
940e8f0
to
61b414a
Compare
new Faker
use
This needs to be rebased |
8e4d8ee
to
1a46b5e
Compare
I saw that there's a
Faker
class being exported now, so I tried to use it, but it doesn't seem to work.For example, when trying to do
faker = new Faker(); faker.name.firstName()
I get:I didn't see any examples of using this constructor in the docs, so it's possible I'm using it wrong. Anyway, I wrote these tests to check if it was a problem in my own project, but they fail as well in the same way.