Gab*_*iel 9 javascript sinon reactjs okta-api cypress
我想用 Cypress 创建一个测试,它有一个 React 组件,该组件使用@okta/okta-react
带有 HOC ( withOktaAuth
)的 auth 库( )。
我的组件如下所示:
// Welcome.js
import { withOktaAuth } from '@okta/okta-react'
const Welcome = ({authState}) => {
return <div>{authState.isAuthenticated ? 'stubbed' : 'not working'}</div>
}
export default withOktaAuth(Welcome)
Run Code Online (Sandbox Code Playgroud)
我试着做一个这样的测试:
// test.js
import * as OktaReact from '@okta/okta-react'
const withOktaAuthStub = Component => {
Component.defaultProps = {
...Component.defaultProps,
authState: {
isAuthenticated: true,
isPending: false
},
authService: {
accessToken: '123'
}
}
return Component
}
describe('Test auth', () => {
before(() => {
cy.stub(OktaReact, 'withOktaAuth').callsFake(withOktaAuthStub)
})
it('Stubs auth', () => {
cy.visit('/welcome')
cy.contains('stubbed')
})
})
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,该组件仍然没有使用 stubbed 函数。很感谢任何形式的帮助!
小智 1
这个问题提交已经过去了 2 年,但对于那些仍然遇到该错误的人,Cypress 提供了有关 Okta e2e 测试的指南:https://docs.cypress.io/guides/end-to-end-testing/okta-身份验证#调整后端
归档时间: |
|
查看次数: |
1165 次 |
最近记录: |