gpt4 book ai didi

angular - 在 beforeEach 中声明变量

转载 作者:行者123 更新时间:2023-12-03 15:57:25 26 4
gpt4 key购买 nike

我得到

ReferenceError: initialState is not defined



当我在 beforeEach(()=> {... 中将 initialState 声明为 const 时.那不应该工作吗?

describe('register reducer', () => {
beforeEach(() => {
const initialState = UsersService.getInitialUsersState();
})

it('should return the initial state', () => {
expect(usersReducer(undefined, [])).toEqual(initialState);
});

it('Toggle isBaby or sitter', () => {
deepFreeze(initialState);
let newState = initialState;
newState.isBaby = true;

expect(
usersReducer(initialState, {
type: types.UsersActions.SET_TYPE,
payload: true
})).toEqual(newState);
});

最佳答案

虽然beforeEach确实如此在每次测试之前运行,如果你这样做,initialState仅在 beforeEach 的范围内可见,改成这样:

describe('register reducer', () => {
let initialState;
beforeEach(() => {
initialState = UsersService.getInitialUsersState();
})
...

关于angular - 在 beforeEach 中声明变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50580235/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com