Each adds a new component, should write the corresponding test.

  • Create a testdocument in a folder inside the component, and then create a inside index.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 a render method and fixtures 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 to document.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.jscreating default.jsonand 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.jsin the way you need to in index.spec.jswriting in the unit test:

    • Each determination is adiscribe('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 is component.jsin the this. Pass thisof inputthe contents should be in default.jsonthe 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 also toBe()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 -uattention plus the option to update. The first test run will automatically generate __snapshots__documents folder, and move into the json document.