forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list-spec.js
40 lines (35 loc) · 1.22 KB
/
list-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/// <reference types="cypress" />
const allUsers = require('../fixtures/users.json')
// you can even require another JavaScript file
// and use whatever was exported there
const { names } = require('../fixtures/names')
// sanity check
expect(names, 'list of names').to.be.an('array')
describe('array fixture', () => {
it('iterates over a list', () => {
cy.fixture('users').then((users) => {
expect(users).to.be.an('array').and.to.have.have.length(3)
users.forEach((user) => {
expect(user).to.have.keys(['name', 'age'])
expect(user.age).to.be.a('number').and.be.gt(10).and.be.lt(100)
})
})
})
// we can dynamically create tests from a static JSON list
// that we have loaded using "require" or "import" statement
// for more examples, see "Dynamic tests" recipes
allUsers.forEach((user) => {
it(`has user ${user.name}`, () => {
cy.wrap(user).should('have.property', 'name', user.name)
cy.wrap(user).should('have.property', 'age', user.age)
})
})
context('imported names', () => {
// create a test for each name
names.forEach((name) => {
it(`"${name}" has first and last name`, () => {
expect(name).to.match(/^\w+ \w+$/)
})
})
})
})