Skip to content

Commit 432d44b

Browse files
authored
Type check specs 71 (#82)
* 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
1 parent 360d215 commit 432d44b

File tree

10 files changed

+743
-619
lines changed

10 files changed

+743
-619
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
save-exact=true
2+
package-lock=true

circle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ jobs:
2222
- ~/.npm
2323
- ~/.cache
2424
- .git
25+
- run: npm run types
2526
- run: npm run test:ci:record

cypress/integration/examples/assertions.spec.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ context('Assertions', () => {
3333
cy.get('.assertions-p').find('p')
3434
.should(($p) => {
3535
// return an array of texts from all of the p's
36-
let texts = $p.map((i, el) => // https://on.cypress.io/$
36+
// @ts-ignore TS6133 unused variable
37+
const texts = $p.map((i, el) => // https://on.cypress.io/$
3738
Cypress.$(el).text())
3839

3940
// jquery map returns jquery object
4041
// and .get() convert this to simple array
41-
texts = texts.get()
42+
const paragraphs = texts.get()
4243

4344
// array should have length of 3
44-
expect(texts).to.have.length(3)
45+
expect(paragraphs).to.have.length(3)
4546

4647
// set this specific subject
47-
expect(texts).to.deep.eq([
48+
expect(paragraphs).to.deep.eq([
4849
'Some text from first p',
4950
'More text from second p',
5051
'And even more text from third p',

cypress/integration/examples/cypress_api.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ context('Cypress.Commands', () => {
1818
method = method || 'log'
1919

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

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

31+
// @ts-ignore TS2339
3032
// eslint-disable-next-line no-unused-vars
3133
cy.get('button').console('info').then(($button) => {
3234
// subject is still $button
@@ -89,6 +91,7 @@ context('Cypress.Server', () => {
8991
// eslint-disable-next-line no-unused-vars
9092
whitelist (xhr) {
9193
// handle custom logic for whitelisting
94+
expect(xhr).to.be.an('object')
9295
},
9396
})
9497
})

cypress/integration/examples/navigation.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ context('Navigation', () => {
4646
timeout: 50000, // increase total time for the visit to resolve
4747
onBeforeLoad (contentWindow) {
4848
// contentWindow is the remote page's window object
49+
expect(typeof contentWindow === 'object').to.be.true
4950
},
5051
onLoad (contentWindow) {
5152
// contentWindow is the remote page's window object
53+
expect(typeof contentWindow === 'object').to.be.true
5254
},
5355
})
5456
/* eslint-enable no-unused-vars */

cypress/integration/examples/spies_stubs_clocks.spec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ context('Spies, Stubs, and Clock', () => {
2121
cy.visit('http://localhost:8080/commands/spies-stubs-clocks')
2222

2323
let obj = {
24-
foo () {},
24+
/**
25+
* prints both arguments to the console
26+
* @param a {string}
27+
* @param b {string}
28+
*/
29+
foo (a, b) {
30+
// eslint-disable-next-line no-console
31+
console.log('a', a, 'b', b)
32+
},
2533
}
2634

2735
let stub = cy.stub(obj, 'foo').as('foo')

cypress/integration/examples/utilities.spec.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,36 @@ context('Utilities', () => {
4646

4747
it('Cypress.minimatch - test out glob patterns against strings', () => {
4848
// https://on.cypress.io/minimatch
49-
Cypress.minimatch('/users/1/comments', '/users/*/comments', {
49+
let matching = Cypress.minimatch('/users/1/comments', '/users/*/comments', {
5050
matchBase: true,
5151
})
52+
expect(matching, 'matching wildcard').to.be.true
53+
54+
matching = Cypress.minimatch("/users/1/comments/2", "/users/*/comments", {
55+
matchBase: true
56+
})
57+
expect(matching, 'comments').to.be.false
58+
59+
// ** matches against all downstream path segments
60+
matching = Cypress.minimatch("/foo/bar/baz/123/quux?a=b&c=2", "/foo/**", {
61+
matchBase: true
62+
})
63+
expect(matching, 'comments').to.be.true
64+
65+
// whereas * matches only the next path segment
66+
67+
matching = Cypress.minimatch("/foo/bar/baz/123/quux?a=b&c=2", "/foo/*", {
68+
matchBase: false
69+
})
70+
expect(matching, 'comments').to.be.false
5271
})
5372

5473

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

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

89+
/**
90+
* @return Bluebird<string>
91+
*/
6992
function waitOneSecond () {
7093
// return a promise that resolves after 1 second
94+
// @ts-ignore TS2351 (new Cypress.Promise)
7195
// eslint-disable-next-line no-unused-vars
7296
return new Cypress.Promise((resolve, reject) => {
7397
setTimeout(() => {
@@ -83,6 +107,7 @@ context('Utilities', () => {
83107
cy.then(() =>
84108
// return a promise to cy.then() that
85109
// is awaited until it resolves
110+
// @ts-ignore TS7006
86111
waitOneSecond().then((str) => {
87112
expect(str).to.eq('foo')
88113
expect(waited).to.be.true

0 commit comments

Comments
 (0)