-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add list fixture specs * add array assertion * update expected filename
- Loading branch information
Showing
5 changed files
with
72 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
examples/fundamentals__fixtures/cypress/fixtures/users.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"name": "Joe Bravo", | ||
"age": 20 | ||
}, | ||
{ | ||
"name": "Mike Smith", | ||
"age": 30 | ||
}, | ||
{ | ||
"name": "Alicia Blue", | ||
"age": 25 | ||
} | ||
] |
25 changes: 25 additions & 0 deletions
25
examples/fundamentals__fixtures/cypress/integration/list-spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/// <reference types="cypress" /> | ||
const allUsers = require('../fixtures/users.json') | ||
|
||
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) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
examples/fundamentals__fixtures/cypress/integration/sanity-js-spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/// <reference types="cypress" /> | ||
|
||
// bundled "os" module does not have the right EOL | ||
// thus we need to set it based on the platform ourself | ||
const EOL = Cypress.platform === 'win32' ? '\\' : '/' | ||
|
||
/** | ||
* Joins parts of the file path using the EOL | ||
* @example | ||
* join('cypress', 'integration') | ||
* // "cypress/integration" on non-Windows | ||
* // "cypress\integration" on Windows | ||
*/ | ||
const join = (...paths) => paths.join(EOL) | ||
|
||
describe('sanity JavaScript tests', () => { | ||
// confirm that the spec information is present | ||
|
||
it('has __dirname', () => { | ||
expect(__dirname).to.be.a('string') | ||
// on Windows OS the directory is "cypress\integration" | ||
// on other operating systems it is "cypress/integration" | ||
expect(__dirname).to.equal(join('cypress', 'integration')) | ||
}) | ||
|
||
it('has __filename', () => { | ||
expect(__filename).to.be.a('string') | ||
expect(__filename).to.equal( | ||
join('cypress', 'integration', 'sanity-js-spec.js') | ||
) | ||
}) | ||
}) |