Each adds a new component, should write the corresponding test.
-
Create a
test
document in a folder inside the component, and then create a insideindex.spec.js
.Inside this
const { render, fixtures } = require('marko-tester')('../index.marko’);
explanation:marko-tester
returns a function for you to use. Pass a relative path to a marko component file and you will receive arender
method andfixtures
method/object. By default this will run JEST SnapShots test for the fixtures of the component.-
render
- a method that renders a component with a given input and mounts it todocument.body
. The mounted component instance is returned. -
fixtures
- an object that contains all fixtures that are found within the__snapshots__
folder for the component. You can get content of a fixture by specifying a filename:fixtures[FixtureFileName]
.
-
-
Listed in
index.spec.js
creatingdefault.json
and json other documents, this is the place to store mock data input. Inside is calling this component of the outer layer of marko to this component passed all parameters. Each have their own json document in this set of parameters. The change can be copied from the browser inside. What is the specific value of the data is not important, as long as the test can get on the line. -
If this component has
component.js
in the way you need to inindex.spec.js
writing in the unit test:-
Each determination is a
discribe('discription of the scenario' () => {methods});
There is first defined
const component = render(fixtures.default);
, (only default?) Out of this component is to render this component, which iscomponent.js
in thethis
. Passthis
ofinput
the contents should be indefault.json
the order defined by (this.xxx
). -
Next, define the parameters of our mock required, it can be defined as a JSON object. log out of the test methods in the incoming parameters, directly into the mock data after copy down inside that part of JSON next scenario we tested needed. Outermost string in single quotes innermost double quotes.
-
Then call
component.testFunc(mockData);
, after the judge sentences as follows:it('this.state.msg should be "scheduledMsg"', () => { expect(component.state.msg).toEqual('scheduledMsg'); });
Here
toEqual()
are alsotoBe()
replaced in specific unknown origin. -
Full judgment finished, before the end describe, have
afterEach(() => { component.destroy(); });
Destroy this component, or will fall into an infinite loop.
-
-
After each change the test document, run
$ yarn test -u
attention plus the option to update. The first test run will automatically generate__snapshots__
documents folder, and move into the json document.