Closed hjoelh closed 1 year ago
@yusinto Does this make sense? Could I open a PR?
Hello @hjoelh, sorry for the late reply. The description sounds reason, so if you can, it will be a great help to Open a PR for this.
This has been fixed in #57 (thank you @hjoelh for the pr!). A new version will be released soon which will include this fix. Stay tuned for an update.
Describe the bug mockUseFlags returns undefined, this breaks application code as the expected type of useFlags is a function that returns LDFlagSet type (empty object/object of string keys and values of any).
This has the unfortunate effect of breaking any unmocked tests that include a useFlags call, which would without this package added to jest setup pass/run fine as useFlags will just return {} with a property access returning undefined (essentially flag is false/off if handled with a fasly check). When this package is added it will break any unmocked useFlags calls.
To reproduce Fork this https://replit.com/@hjoelh/launchdarklybugtest?v=1 run
npm run test
, you should see a fail go to jest.config.js comment out "jest-launchdarkly-mock" runnpm run test
, you should see pass with someFlag logging as undefinedExpected behavior When adding "jest-launchdarkly-mock" to jest setup, mockUseFlags should return a function that returns an empty object so that application code behaves as expected.
Way to fix I think: set
mockUseFlags.mockImplementation(() => ({}));
after initialising mockUseFlags ensure this mockImplementation is also set aftermockUseFlags.mockReset()
call, (I am assuming mockReset will make mockUseFlags undefined again)SDK version See replit
Language version, developer tools See replit
OS/platform See replit
Additional context Please let me know if I have got this wrong/misunderstood, otherwise I am happy to open a PR.
Thanks! 😀