Closed scottnath closed 1 year ago
Thanks for submitting this @scottnath! Had a couple of questions going through it initially:
describe
/it
?expect
library across test environments? Seems like in this case we are merging them together?Also, it seems like chai may be overriding the Jest assertions in that:
expect(TestParser).to.exist;
expect(TestParser).to.be.a('function');
expect(Itter).to.exist;
expect(Itter).to.be.a('function');
expect(GetDomFragment).to.exist;
expect(GetDomFragment).to.be.a('function');
Would be written like this in Jest (I think):
expect(TestParser).toBeDefined();
expect(TestParser).toEqual(expect.any(Function));
Changelog
New
chai
as assertion libraryWhat is this?
This is the parser which parses the exportable tests.
This parser, with our exportable-test structure, is now confirmed to work with Jest (this repo) and Mocha. The exportable tests have been confirmed to work in Angular CLI environments.
Exportable test parser
This test parser is meant to create
describe
/it
/expect
test structures. If it's output was being printed out, it would look like any other describe/it tests:Exportable test structure
Inside
src/test-parser.js
is the breakdown of an exportable test object's available properties - documented in thescenario-test-object
typedef JSDoc block.The example in this repo via the fixture (see below) is a very basic example of a test.
Test fixtures
PR includes fixtures for the tests which are:
standardDiv
is the one test. This test only checks the content of the HTMLexpect
functions is why I addedchai
. Jest's assertion library doesn't allow that parameter out of the boxHow Jest runs the tests
yarn test
triggers the tests insidesrc/__tests__/test-parser-test.js
div--variant-one.html
TestParser
(the test parsing func) usingdocument
- which contains the DOM fragmentNext steps
Real-world example
This PR only includes testing of a basic example-fixture.
@elizabethsjudd is working on an actual test for the
accordion
component which will include separate tests per user type. Her tests will show how to test changes to the DOM using this exportable test format.Carbon POC
While we can get these tests running in this environment, we should also test that they could work within one of carbon-components-react/angular/vue.
Chai assertions / assertion library selection
The second parameter allows us to tie the
expect
statements to a specific scenario-requirement. But we don't want to mix the assertion types. The assertion library for these exportable tests should be something that would work in at least all four framework test environments, plus Selenium.Confirming all requirements are met
We have tests which reads the Gherkin and the exportable tests and determines if there is a test for every requirement. I didn't want to include that in this PR so that we can focus on the exportable test structure