-
Notifications
You must be signed in to change notification settings - Fork 259
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
Add a sample test to prove tests work when Okta is integrated #129
Comments
@mraible Thanks for adding this ticket to track the issue. Internal Ref: OKTA-322158 |
@swiftone This sounds a lot like another GH issue we have seen. okta/okta-oidc-js#846 |
@aarongranick-okta The change in 3.0.3 changed logic to use emitter from 'auth-js', but looks like for some reason the Wondering should we just put the |
We've already had problems with bundling auth-js in the widget, I don't think we want to bundle it more, particularly for okta-react where people can already follow our guides and pull it in independently. |
@mraible I am successfully reproduced your issue in the sample repo. I also tried to print the authJs instance, then it turns out the test env picked the server bundle instead of the browser one. Below is the log (check the userAgent):
|
@mraible It's configurable in jest (https://jest-bot.github.io/jest/docs/configuration.html#browser-boolean) and no mock is needed. |
@shuowu I tried adding the following to my "jest": {
"browser": true
} This results in an error:
All I'm doing is creating a React app with Create React App, then adding our SDK. CRA creates a test as part of the process and as soon as you add Okta's React SDK, that test starts failing. |
The reason is the test env picked the server bundle which is missing the |
@mraible Here is the jest "browser" config we are using: https://github.com/okta/okta-auth-js/blob/dev-4.0/jest.browser.js The "moduleNameMapper" lets you map any module name to any path you specify. Because jest is running in node, by default it will pull the node version of the module (the "main" entry in package.json). Webpacked / browser code would use the "browser" entry from the module. https://github.com/okta/okta-auth-js/blob/master/packages/okta-auth-js/package.json#L7 Something like this in your Jest config should work:
|
💥 That worked! Adding the following to my "jest": {
"moduleNameMapper": {
"^@okta/okta-auth-js$": "<rootDir>/node_modules/@okta/okta-auth-js/dist/okta-auth-js.min.js"
}
} |
@shuowu do we need to fix this sample with the jest config mentioned above? |
@robertjd There is no test in this sample repo. The jest config is for tests in Matt's repo. |
I think it'd be wise to add a test to this repo to show others that this extra step is needed. |
With Okta React 3.0.4, I get a test failure after creating an app and adding the SDK.
I don’t get this error with 3.0.1. Proof in https://github.com/mraible/schematics/pull/1.
I tried to modify my test to mock tiny-emitter, but it still doesn’t work.
The text was updated successfully, but these errors were encountered: