Closed pyrossh closed 7 years ago
I got same problem here.
I fixed this problem by modifying this line:
const { effects, getState } = wrapComponentWithState();
to
const { effects, getState } = new (wrapComponentWithState())(null, {});
This can pass the test, but i think it's kind of weird...
Actually, I also find some other test example a few small problems:
Like, state template
:
import { provideState } from "freactal";
export const wrapComponentWithState = provideState({
initialState: () => ({
givenName: "Walter",
familyName: "Harriman"
}),
effects: {
setGivenName: softUpdate((state, val) => ({ givenName: val })), // softUpdate not imported
setFamilyName: softUpdate((state, val) => ({ familyName: val }))
},
computed: {
fullName: ({ givenName, familyName }) => `${givenName} ${familyName}`,
greeting: ({ fullName }) => `Hi, ${fullName}, and welcome!`
}
});
It should import softUpdate
the first line.
import { provideState, softUpdate } from "freactal";
Also, Stateless functional components
:
/*** app.spec.js ***/
import { mount } from "enzyme";
// Make sure to import the _unwrapped_ component here!
import { App } from "./app";
// We'll be re-using these values, so let's put it here for convenience.
const state = {
givenName: "Charlie",
familyName: "In-the-box",
fullName: "Charlie In-the-box",
greeting: "Howdy there, kid!"
};
describe("my app", () => {
it("displays a greeting to the user", () => {
// This test should be easy - all we have to do is ensure that
// the string that is passed in is displayed correctly!
// We're not doing anything with effects here, so let's not bother
// setting them for now...
const effects = {};
// First, we mount the component, providing the expected state and effects.
const el = mount(<App state={state} effects={effects}>);
// And then we can make assertions on the output.
expect(el.find("#greeting").text()).to.equal("Howdy there, kid!");
});
it("accepts changes to the given name", () => {
// Next we're testing the conditions under which our component might
// interact with the provided effects.
const effects = {
setGivenName: sinon.spy(),
setFamilyName: sinon.spy()
};
const el = mount(<App state={state} effects={effects}>);
// Using `sinon-chai`, we can make readable assertions about whether
// a spy function has been called. We don't expect our effect to
// be invoked when the component mounts, so let's make that assertion
// here.
expect(effects.setGivenName).not.to.have.been.called;
// Next, we can simulate a input-box value change.
el.find("input.given").simulate("change", {
target: { value: "Eric" }
});
// And finally, we can assert that the effect - or, rather, the Sinon
// spy that is standing in for the effect - was invoked with the expected
// value.
expect(effects.setGivenName).to.have.been.calledWith("Eric");
});
});
const el = mount(<App state={state} effects={effects}>);
This component does't have a close tag, so it can't pass...
Should be fixed:
const el = mount(<App state={state} effects={effects}/>)
Thanks the insight @henryluki (for the docs PR!). @pyros2097, this is now fixed in master and will be released on npm
shortly.
The testing the state container part of the Readme doesn't work.
This is the output I'm getting,
I'm using,
babel-node 6.24.0