I get
ReferenceError: initialState is not defined
when I declare initialState as const in beforeEach(()=> {...
. Shouldn't that supposed to work ?
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);
});
While it's true that beforeEach
runs before each test, if you do it that way, initialState
is only visible in the scope of beforeEach
, change it to this:
describe('register reducer', () => {
let initialState;
beforeEach(() => {
initialState = UsersService.getInitialUsersState();
})
...
this question is really old, but just putting a working example here for others that come across this question. here's one way you could do it:
describe('register reducer', () => {
let initialState
beforeEach(() => {
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)
})
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With