-
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
test: add basic unit test - OKTA-327875 #149
Conversation
"okta-hosted-login-server": "npm start --prefix okta-hosted-login/", | ||
"test:okta-hosted-login": "export TEST_TYPE=implicit || setx TEST_TYPE \"implicit\" && protractor okta-oidc-tck/e2e-tests/okta-hosted-login/conf.js", | ||
"custom-login-server": "npm start --prefix custom-login/", | ||
"test:custom-login": "export TEST_TYPE=implicit || setx TEST_TYPE \"implicit\" && protractor okta-oidc-tck/e2e-tests/custom-login/conf.js", | ||
"resource-server": "node scripts/node-resource-server.js", | ||
"test:unit": "npm run test --prefix okta-hosted-login/ && npm run test --prefix custom-login/", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sold on having the root level use npm run test:unit
while the individual packages use npm run test
, but I'm not 100% against it either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about use test:unit
in both places for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After checking the code generated from create-react-app
, I think it might make sense to keep the current naming conventions. As test
in each individual package matches the script generated from CRA
. And the root level test:unit
is for the CI usage.
let container; | ||
|
||
beforeEach(() => { | ||
container = document.createElement('div'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's copied from https://github.com/mraible/schematics/blob/main/src/add-auth/react/src/App.test.js
looks like mount
should be enough here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after checking the doc, it's the suggested way from react test utils
Ref: https://reactjs.org/docs/test-utils.html#act
b3526d1
to
47d4c95
Compare
47d4c95
to
21ed679
Compare
custom-login/package.json
Outdated
}, | ||
"jest": { | ||
"moduleNameMapper": { | ||
"^@okta/okta-auth-js$": "<rootDir>/node_modules/@okta/okta-auth-js/dist/okta-auth-js.min.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"^@okta/okta-auth-js$": "<rootDir>/node_modules/@okta/okta-auth-js/dist/okta-auth-js.min.js" | |
"^@okta/okta-auth-js$": "<rootDir>/node_modules/@okta/okta-auth-js/dist/okta-auth-js.umd.js" |
This is what fixed the tests for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally figured out I was missing the MemoryRouter
from react-router-dom
for jest test.
okta-hosted-login/package.json
Outdated
}, | ||
"jest": { | ||
"moduleNameMapper": { | ||
"^@okta/okta-auth-js$": "<rootDir>/node_modules/@okta/okta-auth-js/dist/okta-auth-js.min.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"^@okta/okta-auth-js$": "<rootDir>/node_modules/@okta/okta-auth-js/dist/okta-auth-js.min.js" | |
"^@okta/okta-auth-js$": "<rootDir>/node_modules/@okta/okta-auth-js/dist/okta-auth-js.umd.js" |
Add basic unit tests for demo purposes per how to handle
okta-auth-js
dep issue.Resolves: #129