Skip to content

Instantly share code, notes, and snippets.

@daniilgri
Last active February 28, 2020 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniilgri/a02ada2eab23788e3ee45208976927a7 to your computer and use it in GitHub Desktop.
Save daniilgri/a02ada2eab23788e3ee45208976927a7 to your computer and use it in GitHub Desktop.
import { handleActions } from "redux-actions";
import * as aboutFilmActions from "../actions/aboutFilmActions";
import { Record, List } from "immutable";
const FilmRecord = Record({
title: "",
year: 0,
ageRestriction: 0,
slug: "",
description: "",
genre: List(),
dates: List(),
seats: 0,
price: 0
});
const AboutFilmRecord = Record({
film: new FilmRecord(),
loading: true,
error: ""
});
const aboutFilmReducer = handleActions(
{
[aboutFilmActions.fetchFilmBySlugRequested]: state =>
state.set("loading", true),
[aboutFilmActions.fetchFilmBySlugSucceed]: (state, { payload }) =>
state.set("loading", false).set("film", payload.film),
[aboutFilmActions.fetchFilmBySlugFailed]: (state, { payload }) =>
state.set("loading", false).set("error", payload)
},
new AboutFilmRecord()
);
export default aboutFilmReducer;
import { Record, List } from "immutable";
import aboutFilmReducer from "./aboutFilmReducer";
const FilmRecord = Record({
title: "",
year: 0,
ageRestriction: 0,
slug: "",
description: "",
genre: List(),
dates: List(),
seats: 0,
price: 0
});
const AboutFilmRecord = Record({
film: new FilmRecord(),
loading: true,
error: ""
});
describe("reducer: aboutFilmsReducer", () => {
const initialState = new AboutFilmRecord();
test("is correct initial state", () => {
const nextState = aboutFilmReducer(undefined, {});
expect(initialState.equals(nextState)).toBe(true);
});
});
FAIL src/store/reducer/aboutFilmReducer.test.js
reducer: aboutFilmsReducer
× is correct initial state (29ms)
● reducer: aboutFilmsReducer › is correct initial state
expect(received).toBe(expected) // Object.is equality
Expected: true
Received: false
25 | const nextState = aboutFilmReducer(undefined, {});
26 | console.log(nextState);
> 27 | expect(initialState.equals(nextState)).toBe(true);
| ^
28 | });
29 | });
30 |
at Object.<anonymous> (src/store/reducer/aboutFilmReducer.test.js:27:44)
console.log src/store/reducer/aboutFilmReducer.test.js:26
Record {
__ownerID: undefined,
_values: List {
size: 3,
_origin: 0,
_capacity: 3,
_level: 5,
_root: null,
_tail: undefined,
__ownerID: undefined,
__hash: undefined,
__altered: false
}
}
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 4.015s
Ran all test suites related to changed files.
Watch Usage: Press w to show more.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment