Skip to content

Commit

Permalink
Type check specs 71 (#82)
Browse files Browse the repository at this point in the history
* typechecking some spec files for #71

* type check all files with a few exceptions

* explicit package lock

* working on types in utilities.spec.js

* enable all cy.visit

* update contentWindow test to avoid crashing
  • Loading branch information
bahmutov authored Jun 8, 2018
1 parent 360d215 commit 432d44b
Show file tree
Hide file tree
Showing 10 changed files with 743 additions and 619 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
save-exact=true
package-lock=true
1 change: 1 addition & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ jobs:
- ~/.npm
- ~/.cache
- .git
- run: npm run types
- run: npm run test:ci:record
9 changes: 5 additions & 4 deletions cypress/integration/examples/assertions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ context('Assertions', () => {
cy.get('.assertions-p').find('p')
.should(($p) => {
// return an array of texts from all of the p's
let texts = $p.map((i, el) => // https://on.cypress.io/$
// @ts-ignore TS6133 unused variable
const texts = $p.map((i, el) => // https://on.cypress.io/$
Cypress.$(el).text())

// jquery map returns jquery object
// and .get() convert this to simple array
texts = texts.get()
const paragraphs = texts.get()

// array should have length of 3
expect(texts).to.have.length(3)
expect(paragraphs).to.have.length(3)

// set this specific subject
expect(texts).to.deep.eq([
expect(paragraphs).to.deep.eq([
'Some text from first p',
'More text from second p',
'And even more text from third p',
Expand Down
3 changes: 3 additions & 0 deletions cypress/integration/examples/cypress_api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ context('Cypress.Commands', () => {
method = method || 'log'

// log the subject to the console
// @ts-ignore TS7017
// eslint-disable-next-line no-console
console[method]('The subject is', subject)

Expand All @@ -27,6 +28,7 @@ context('Cypress.Commands', () => {
return subject
})

// @ts-ignore TS2339
// eslint-disable-next-line no-unused-vars
cy.get('button').console('info').then(($button) => {
// subject is still $button
Expand Down Expand Up @@ -89,6 +91,7 @@ context('Cypress.Server', () => {
// eslint-disable-next-line no-unused-vars
whitelist (xhr) {
// handle custom logic for whitelisting
expect(xhr).to.be.an('object')
},
})
})
Expand Down
2 changes: 2 additions & 0 deletions cypress/integration/examples/navigation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ context('Navigation', () => {
timeout: 50000, // increase total time for the visit to resolve
onBeforeLoad (contentWindow) {
// contentWindow is the remote page's window object
expect(typeof contentWindow === 'object').to.be.true
},
onLoad (contentWindow) {
// contentWindow is the remote page's window object
expect(typeof contentWindow === 'object').to.be.true
},
})
/* eslint-enable no-unused-vars */
Expand Down
10 changes: 9 additions & 1 deletion cypress/integration/examples/spies_stubs_clocks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ context('Spies, Stubs, and Clock', () => {
cy.visit('http://localhost:8080/commands/spies-stubs-clocks')

let obj = {
foo () {},
/**
* prints both arguments to the console
* @param a {string}
* @param b {string}
*/
foo (a, b) {
// eslint-disable-next-line no-console
console.log('a', a, 'b', b)
},
}

let stub = cy.stub(obj, 'foo').as('foo')
Expand Down
29 changes: 27 additions & 2 deletions cypress/integration/examples/utilities.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,36 @@ context('Utilities', () => {

it('Cypress.minimatch - test out glob patterns against strings', () => {
// https://on.cypress.io/minimatch
Cypress.minimatch('/users/1/comments', '/users/*/comments', {
let matching = Cypress.minimatch('/users/1/comments', '/users/*/comments', {
matchBase: true,
})
expect(matching, 'matching wildcard').to.be.true

matching = Cypress.minimatch("/users/1/comments/2", "/users/*/comments", {
matchBase: true
})
expect(matching, 'comments').to.be.false

// ** matches against all downstream path segments
matching = Cypress.minimatch("/foo/bar/baz/123/quux?a=b&c=2", "/foo/**", {
matchBase: true
})
expect(matching, 'comments').to.be.true

// whereas * matches only the next path segment

matching = Cypress.minimatch("/foo/bar/baz/123/quux?a=b&c=2", "/foo/*", {
matchBase: false
})
expect(matching, 'comments').to.be.false
})


it('Cypress.moment() - format or parse dates using a moment method', () => {
// https://on.cypress.io/moment
// eslint-disable-next-line no-unused-vars
let time = Cypress.moment().utc('2014-04-25T19:38:53.196Z').format('h:mm A')
const time = Cypress.moment().utc('2014-04-25T19:38:53.196Z').format('h:mm A')
expect(time).to.be.a('string')

cy.get('.utility-moment').contains('3:38 PM')
.should('have.class', 'badge')
Expand All @@ -66,8 +86,12 @@ context('Utilities', () => {
// https://on.cypress.io/promise
let waited = false

/**
* @return Bluebird<string>
*/
function waitOneSecond () {
// return a promise that resolves after 1 second
// @ts-ignore TS2351 (new Cypress.Promise)
// eslint-disable-next-line no-unused-vars
return new Cypress.Promise((resolve, reject) => {
setTimeout(() => {
Expand All @@ -83,6 +107,7 @@ context('Utilities', () => {
cy.then(() =>
// return a promise to cy.then() that
// is awaited until it resolves
// @ts-ignore TS7006
waitOneSecond().then((str) => {
expect(str).to.eq('foo')
expect(waited).to.be.true
Expand Down
Loading

0 comments on commit 432d44b

Please sign in to comment.