br-dionysus 1.7.7 → 1.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -13
- package/attributes.json +1 -1
- package/build/doc.config.ts +1 -1
- package/build/lib.config.ts +1 -1
- package/cypress/component/MInputNumber.cy.ts +38 -0
- package/cypress/component/MSelect.cy.ts +46 -0
- package/cypress/component/MSelectV2.cy.ts +46 -0
- package/cypress/e2e/1-getting-started/todo.cy.js +143 -0
- package/cypress/e2e/2-advanced-examples/actions.cy.js +321 -0
- package/cypress/e2e/2-advanced-examples/aliasing.cy.js +39 -0
- package/cypress/e2e/2-advanced-examples/assertions.cy.js +176 -0
- package/cypress/e2e/2-advanced-examples/connectors.cy.js +98 -0
- package/cypress/e2e/2-advanced-examples/cookies.cy.js +118 -0
- package/cypress/e2e/2-advanced-examples/cypress_api.cy.js +185 -0
- package/cypress/e2e/2-advanced-examples/files.cy.js +85 -0
- package/cypress/e2e/2-advanced-examples/location.cy.js +32 -0
- package/cypress/e2e/2-advanced-examples/misc.cy.js +90 -0
- package/cypress/e2e/2-advanced-examples/navigation.cy.js +55 -0
- package/cypress/e2e/2-advanced-examples/network_requests.cy.js +163 -0
- package/cypress/e2e/2-advanced-examples/querying.cy.js +114 -0
- package/cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js +204 -0
- package/cypress/e2e/2-advanced-examples/storage.cy.js +117 -0
- package/cypress/e2e/2-advanced-examples/traversal.cy.js +121 -0
- package/cypress/e2e/2-advanced-examples/utilities.cy.js +107 -0
- package/cypress/e2e/2-advanced-examples/viewport.cy.js +58 -0
- package/cypress/e2e/2-advanced-examples/waiting.cy.js +30 -0
- package/cypress/e2e/2-advanced-examples/window.cy.js +22 -0
- package/cypress/e2e/spec.cy.ts +5 -0
- package/cypress/e2e/toolCheckType.cy.ts +37 -0
- package/cypress/e2e/toolCompareStructures.cy.ts +19 -0
- package/cypress/e2e/toolCreateHash.cy.ts +7 -0
- package/cypress/e2e/toolMoneyFormat.cy.ts +46 -0
- package/cypress/fixtures/example.json +5 -0
- package/cypress/support/commands.ts +37 -0
- package/cypress/support/component-index.html +12 -0
- package/cypress/support/component.ts +39 -0
- package/cypress/support/e2e.ts +20 -0
- package/cypress/types.d.ts +1 -0
- package/cypress.config.ts +16 -0
- package/dist/br-dionysus.es.js +2774 -2739
- package/dist/br-dionysus.umd.js +7 -7
- package/dist/cypress.config.d.ts +3 -0
- package/dist/index.css +1 -1
- package/dist/packages/MSelectV2/src/MSelectV2.vue.d.ts +8 -2
- package/dist/packages/SkinConfig/src/SkinConfig.vue.d.ts +1 -1
- package/dist/packages/Tool/checkType/checkType.d.ts +7 -0
- package/dist/packages/Tool/compareStructures/compareStructures.d.ts +10 -0
- package/dist/packages/Tool/createHash/createHash.d.ts +7 -0
- package/dist/packages/index.d.ts +6 -2
- package/dist/vite.config.d.ts +2 -0
- package/package.json +7 -3
- package/packages/Hook/useRemainingSpace/demo.vue +0 -1
- package/packages/Hook/useTableConfig/demo.vue +1 -1
- package/packages/MDialog/src/MDialog.vue +2 -8
- package/packages/MInline/src/MInline.vue +1 -11
- package/packages/MInputNumber/src/MInputNumber.vue +3 -5
- package/packages/MSelectV2/docs/demo.vue +1 -1
- package/packages/MSelectV2/src/MSelectV2.vue +10 -6
- package/packages/MTable/src/MTable.vue +2 -2
- package/packages/MTableColumn/src/MTableColumn.vue +51 -8
- package/packages/MTableColumnSet/src/MTableColumnSet.vue +1 -1
- package/packages/SkinConfig/src/SkinConfig.vue +2 -1
- package/packages/SkinConfig/src/useSkin.ts +5 -2
- package/packages/Tool/checkType/README.md +17 -0
- package/packages/Tool/checkType/checkType.ts +14 -0
- package/packages/Tool/compareStructures/README.md +16 -0
- package/packages/Tool/createHash/README.md +7 -0
- package/packages/Tool/moneyFormat/README.md +13 -12
- package/packages/Tool/moneyFormat/moneyFormat.ts +35 -2
- package/packages/index.ts +8 -2
- package/src/cypress-augmentation.d.ts +9 -0
- package/tags.json +1 -1
- package/{build/base.config.ts → vite.config.ts} +3 -3
- package/web-types.json +1 -1
- package/tool/checkType.ts +0 -15
- /package/{tool → packages/Tool/compareStructures}/compareStructures.ts +0 -0
- /package/{tool → packages/Tool/createHash}/createHash.ts +0 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
|
|
3
|
+
context('Network Requests', () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
cy.visit('https://example.cypress.io/commands/network-requests')
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
// Manage HTTP requests in your app
|
|
9
|
+
|
|
10
|
+
it('cy.request() - make an XHR request', () => {
|
|
11
|
+
// https://on.cypress.io/request
|
|
12
|
+
cy.request('https://jsonplaceholder.cypress.io/comments')
|
|
13
|
+
.should((response) => {
|
|
14
|
+
expect(response.status).to.eq(200)
|
|
15
|
+
// the server sometimes gets an extra comment posted from another machine
|
|
16
|
+
// which gets returned as 1 extra object
|
|
17
|
+
expect(response.body).to.have.property('length').and.be.oneOf([500, 501])
|
|
18
|
+
expect(response).to.have.property('headers')
|
|
19
|
+
expect(response).to.have.property('duration')
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('cy.request() - verify response using BDD syntax', () => {
|
|
24
|
+
cy.request('https://jsonplaceholder.cypress.io/comments')
|
|
25
|
+
.then((response) => {
|
|
26
|
+
// https://on.cypress.io/assertions
|
|
27
|
+
expect(response).property('status').to.equal(200)
|
|
28
|
+
expect(response).property('body').to.have.property('length').and.be.oneOf([500, 501])
|
|
29
|
+
expect(response).to.include.keys('headers', 'duration')
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('cy.request() with query parameters', () => {
|
|
34
|
+
// will execute request
|
|
35
|
+
// https://jsonplaceholder.cypress.io/comments?postId=1&id=3
|
|
36
|
+
cy.request({
|
|
37
|
+
url: 'https://jsonplaceholder.cypress.io/comments',
|
|
38
|
+
qs: {
|
|
39
|
+
postId: 1,
|
|
40
|
+
id: 3,
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
.its('body')
|
|
44
|
+
.should('be.an', 'array')
|
|
45
|
+
.and('have.length', 1)
|
|
46
|
+
.its('0') // yields first element of the array
|
|
47
|
+
.should('contain', {
|
|
48
|
+
postId: 1,
|
|
49
|
+
id: 3,
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('cy.request() - pass result to the second request', () => {
|
|
54
|
+
// first, let's find out the userId of the first user we have
|
|
55
|
+
cy.request('https://jsonplaceholder.cypress.io/users?_limit=1')
|
|
56
|
+
.its('body') // yields the response object
|
|
57
|
+
.its('0') // yields the first element of the returned list
|
|
58
|
+
// the above two commands its('body').its('0')
|
|
59
|
+
// can be written as its('body.0')
|
|
60
|
+
// if you do not care about TypeScript checks
|
|
61
|
+
.then((user) => {
|
|
62
|
+
expect(user).property('id').to.be.a('number')
|
|
63
|
+
// make a new post on behalf of the user
|
|
64
|
+
cy.request('POST', 'https://jsonplaceholder.cypress.io/posts', {
|
|
65
|
+
userId: user.id,
|
|
66
|
+
title: 'Cypress Test Runner',
|
|
67
|
+
body: 'Fast, easy and reliable testing for anything that runs in a browser.',
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
// note that the value here is the returned value of the 2nd request
|
|
71
|
+
// which is the new post object
|
|
72
|
+
.then((response) => {
|
|
73
|
+
expect(response).property('status').to.equal(201) // new entity created
|
|
74
|
+
expect(response).property('body').to.contain({
|
|
75
|
+
title: 'Cypress Test Runner',
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
// we don't know the exact post id - only that it will be > 100
|
|
79
|
+
// since JSONPlaceholder has built-in 100 posts
|
|
80
|
+
expect(response.body).property('id').to.be.a('number')
|
|
81
|
+
.and.to.be.gt(100)
|
|
82
|
+
|
|
83
|
+
// we don't know the user id here - since it was in above closure
|
|
84
|
+
// so in this test just confirm that the property is there
|
|
85
|
+
expect(response.body).property('userId').to.be.a('number')
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('cy.request() - save response in the shared test context', () => {
|
|
90
|
+
// https://on.cypress.io/variables-and-aliases
|
|
91
|
+
cy.request('https://jsonplaceholder.cypress.io/users?_limit=1')
|
|
92
|
+
.its('body').its('0') // yields the first element of the returned list
|
|
93
|
+
.as('user') // saves the object in the test context
|
|
94
|
+
.then(function () {
|
|
95
|
+
// NOTE 👀
|
|
96
|
+
// By the time this callback runs the "as('user')" command
|
|
97
|
+
// has saved the user object in the test context.
|
|
98
|
+
// To access the test context we need to use
|
|
99
|
+
// the "function () { ... }" callback form,
|
|
100
|
+
// otherwise "this" points at a wrong or undefined object!
|
|
101
|
+
cy.request('POST', 'https://jsonplaceholder.cypress.io/posts', {
|
|
102
|
+
userId: this.user.id,
|
|
103
|
+
title: 'Cypress Test Runner',
|
|
104
|
+
body: 'Fast, easy and reliable testing for anything that runs in a browser.',
|
|
105
|
+
})
|
|
106
|
+
.its('body').as('post') // save the new post from the response
|
|
107
|
+
})
|
|
108
|
+
.then(function () {
|
|
109
|
+
// When this callback runs, both "cy.request" API commands have finished
|
|
110
|
+
// and the test context has "user" and "post" objects set.
|
|
111
|
+
// Let's verify them.
|
|
112
|
+
expect(this.post, 'post has the right user id').property('userId').to.equal(this.user.id)
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('cy.intercept() - route responses to matching requests', () => {
|
|
117
|
+
// https://on.cypress.io/intercept
|
|
118
|
+
|
|
119
|
+
let message = 'whoa, this comment does not exist'
|
|
120
|
+
|
|
121
|
+
// Listen to GET to comments/1
|
|
122
|
+
cy.intercept('GET', '**/comments/*').as('getComment')
|
|
123
|
+
|
|
124
|
+
// we have code that gets a comment when
|
|
125
|
+
// the button is clicked in scripts.js
|
|
126
|
+
cy.get('.network-btn').click()
|
|
127
|
+
|
|
128
|
+
// https://on.cypress.io/wait
|
|
129
|
+
cy.wait('@getComment').its('response.statusCode').should('be.oneOf', [200, 304])
|
|
130
|
+
|
|
131
|
+
// Listen to POST to comments
|
|
132
|
+
cy.intercept('POST', '**/comments').as('postComment')
|
|
133
|
+
|
|
134
|
+
// we have code that posts a comment when
|
|
135
|
+
// the button is clicked in scripts.js
|
|
136
|
+
cy.get('.network-post').click()
|
|
137
|
+
cy.wait('@postComment').should(({ request, response }) => {
|
|
138
|
+
expect(request.body).to.include('email')
|
|
139
|
+
expect(request.headers).to.have.property('content-type')
|
|
140
|
+
expect(response && response.body).to.have.property('name', 'Using POST in cy.intercept()')
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
// Stub a response to PUT comments/ ****
|
|
144
|
+
cy.intercept({
|
|
145
|
+
method: 'PUT',
|
|
146
|
+
url: '**/comments/*',
|
|
147
|
+
}, {
|
|
148
|
+
statusCode: 404,
|
|
149
|
+
body: { error: message },
|
|
150
|
+
headers: { 'access-control-allow-origin': '*' },
|
|
151
|
+
delayMs: 500,
|
|
152
|
+
}).as('putComment')
|
|
153
|
+
|
|
154
|
+
// we have code that puts a comment when
|
|
155
|
+
// the button is clicked in scripts.js
|
|
156
|
+
cy.get('.network-put').click()
|
|
157
|
+
|
|
158
|
+
cy.wait('@putComment')
|
|
159
|
+
|
|
160
|
+
// our 404 statusCode logic in scripts.js executed
|
|
161
|
+
cy.get('.network-put-comment').should('contain', message)
|
|
162
|
+
})
|
|
163
|
+
})
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
|
|
3
|
+
context('Querying', () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
cy.visit('https://example.cypress.io/commands/querying')
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
// The most commonly used query is 'cy.get()', you can
|
|
9
|
+
// think of this like the '$' in jQuery
|
|
10
|
+
|
|
11
|
+
it('cy.get() - query DOM elements', () => {
|
|
12
|
+
// https://on.cypress.io/get
|
|
13
|
+
|
|
14
|
+
cy.get('#query-btn').should('contain', 'Button')
|
|
15
|
+
|
|
16
|
+
cy.get('.query-btn').should('contain', 'Button')
|
|
17
|
+
|
|
18
|
+
cy.get('#querying .well>button:first').should('contain', 'Button')
|
|
19
|
+
// ↲
|
|
20
|
+
// Use CSS selectors just like jQuery
|
|
21
|
+
|
|
22
|
+
cy.get('[data-test-id="test-example"]').should('have.class', 'example')
|
|
23
|
+
|
|
24
|
+
// 'cy.get()' yields jQuery object, you can get its attribute
|
|
25
|
+
// by invoking `.attr()` method
|
|
26
|
+
cy.get('[data-test-id="test-example"]')
|
|
27
|
+
.invoke('attr', 'data-test-id')
|
|
28
|
+
.should('equal', 'test-example')
|
|
29
|
+
|
|
30
|
+
// or you can get element's CSS property
|
|
31
|
+
cy.get('[data-test-id="test-example"]')
|
|
32
|
+
.invoke('css', 'position')
|
|
33
|
+
.should('equal', 'static')
|
|
34
|
+
|
|
35
|
+
// or use assertions directly during 'cy.get()'
|
|
36
|
+
// https://on.cypress.io/assertions
|
|
37
|
+
cy.get('[data-test-id="test-example"]')
|
|
38
|
+
.should('have.attr', 'data-test-id', 'test-example')
|
|
39
|
+
.and('have.css', 'position', 'static')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('cy.contains() - query DOM elements with matching content', () => {
|
|
43
|
+
// https://on.cypress.io/contains
|
|
44
|
+
cy.get('.query-list')
|
|
45
|
+
.contains('bananas')
|
|
46
|
+
.should('have.class', 'third')
|
|
47
|
+
|
|
48
|
+
// we can pass a regexp to `.contains()`
|
|
49
|
+
cy.get('.query-list')
|
|
50
|
+
.contains(/^b\w+/)
|
|
51
|
+
.should('have.class', 'third')
|
|
52
|
+
|
|
53
|
+
cy.get('.query-list')
|
|
54
|
+
.contains('apples')
|
|
55
|
+
.should('have.class', 'first')
|
|
56
|
+
|
|
57
|
+
// passing a selector to contains will
|
|
58
|
+
// yield the selector containing the text
|
|
59
|
+
cy.get('#querying')
|
|
60
|
+
.contains('ul', 'oranges')
|
|
61
|
+
.should('have.class', 'query-list')
|
|
62
|
+
|
|
63
|
+
cy.get('.query-button')
|
|
64
|
+
.contains('Save Form')
|
|
65
|
+
.should('have.class', 'btn')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('.within() - query DOM elements within a specific element', () => {
|
|
69
|
+
// https://on.cypress.io/within
|
|
70
|
+
cy.get('.query-form').within(() => {
|
|
71
|
+
cy.get('input:first').should('have.attr', 'placeholder', 'Email')
|
|
72
|
+
cy.get('input:last').should('have.attr', 'placeholder', 'Password')
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('cy.root() - query the root DOM element', () => {
|
|
77
|
+
// https://on.cypress.io/root
|
|
78
|
+
|
|
79
|
+
// By default, root is the document
|
|
80
|
+
cy.root().should('match', 'html')
|
|
81
|
+
|
|
82
|
+
cy.get('.query-ul').within(() => {
|
|
83
|
+
// In this within, the root is now the ul DOM element
|
|
84
|
+
cy.root().should('have.class', 'query-ul')
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('best practices - selecting elements', () => {
|
|
89
|
+
// https://on.cypress.io/best-practices#Selecting-Elements
|
|
90
|
+
cy.get('[data-cy=best-practices-selecting-elements]').within(() => {
|
|
91
|
+
// Worst - too generic, no context
|
|
92
|
+
cy.get('button').click()
|
|
93
|
+
|
|
94
|
+
// Bad. Coupled to styling. Highly subject to change.
|
|
95
|
+
cy.get('.btn.btn-large').click()
|
|
96
|
+
|
|
97
|
+
// Average. Coupled to the `name` attribute which has HTML semantics.
|
|
98
|
+
cy.get('[name=submission]').click()
|
|
99
|
+
|
|
100
|
+
// Better. But still coupled to styling or JS event listeners.
|
|
101
|
+
cy.get('#main').click()
|
|
102
|
+
|
|
103
|
+
// Slightly better. Uses an ID but also ensures the element
|
|
104
|
+
// has an ARIA role attribute
|
|
105
|
+
cy.get('#main[role=button]').click()
|
|
106
|
+
|
|
107
|
+
// Much better. But still coupled to text content that may change.
|
|
108
|
+
cy.contains('Submit').click()
|
|
109
|
+
|
|
110
|
+
// Best. Insulated from all changes.
|
|
111
|
+
cy.get('[data-cy=submit]').click()
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
})
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
|
|
3
|
+
context('Spies, Stubs, and Clock', () => {
|
|
4
|
+
it('cy.spy() - wrap a method in a spy', () => {
|
|
5
|
+
// https://on.cypress.io/spy
|
|
6
|
+
cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
|
|
7
|
+
|
|
8
|
+
const obj = {
|
|
9
|
+
foo () {},
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const spy = cy.spy(obj, 'foo').as('anyArgs')
|
|
13
|
+
|
|
14
|
+
obj.foo()
|
|
15
|
+
|
|
16
|
+
expect(spy).to.be.called
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('cy.spy() retries until assertions pass', () => {
|
|
20
|
+
cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
|
|
21
|
+
|
|
22
|
+
const obj = {
|
|
23
|
+
/**
|
|
24
|
+
* Prints the argument passed
|
|
25
|
+
* @param x {any}
|
|
26
|
+
*/
|
|
27
|
+
foo (x) {
|
|
28
|
+
console.log('obj.foo called with', x)
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
cy.spy(obj, 'foo').as('foo')
|
|
33
|
+
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
obj.foo('first')
|
|
36
|
+
}, 500)
|
|
37
|
+
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
obj.foo('second')
|
|
40
|
+
}, 2500)
|
|
41
|
+
|
|
42
|
+
cy.get('@foo').should('have.been.calledTwice')
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('cy.stub() - create a stub and/or replace a function with stub', () => {
|
|
46
|
+
// https://on.cypress.io/stub
|
|
47
|
+
cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
|
|
48
|
+
|
|
49
|
+
const obj = {
|
|
50
|
+
/**
|
|
51
|
+
* prints both arguments to the console
|
|
52
|
+
* @param a {string}
|
|
53
|
+
* @param b {string}
|
|
54
|
+
*/
|
|
55
|
+
foo (a, b) {
|
|
56
|
+
console.log('a', a, 'b', b)
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const stub = cy.stub(obj, 'foo').as('foo')
|
|
61
|
+
|
|
62
|
+
obj.foo('foo', 'bar')
|
|
63
|
+
|
|
64
|
+
expect(stub).to.be.called
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('cy.clock() - control time in the browser', () => {
|
|
68
|
+
// https://on.cypress.io/clock
|
|
69
|
+
|
|
70
|
+
// create the date in UTC so it's always the same
|
|
71
|
+
// no matter what local timezone the browser is running in
|
|
72
|
+
const now = new Date(Date.UTC(2017, 2, 14)).getTime()
|
|
73
|
+
|
|
74
|
+
cy.clock(now)
|
|
75
|
+
cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
|
|
76
|
+
cy.get('#clock-div').click()
|
|
77
|
+
cy.get('#clock-div')
|
|
78
|
+
.should('have.text', '1489449600')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('cy.tick() - move time in the browser', () => {
|
|
82
|
+
// https://on.cypress.io/tick
|
|
83
|
+
|
|
84
|
+
// create the date in UTC so it's always the same
|
|
85
|
+
// no matter what local timezone the browser is running in
|
|
86
|
+
const now = new Date(Date.UTC(2017, 2, 14)).getTime()
|
|
87
|
+
|
|
88
|
+
cy.clock(now)
|
|
89
|
+
cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
|
|
90
|
+
cy.get('#tick-div').click()
|
|
91
|
+
cy.get('#tick-div')
|
|
92
|
+
.should('have.text', '1489449600')
|
|
93
|
+
|
|
94
|
+
cy.tick(10000) // 10 seconds passed
|
|
95
|
+
cy.get('#tick-div').click()
|
|
96
|
+
cy.get('#tick-div')
|
|
97
|
+
.should('have.text', '1489449610')
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('cy.stub() matches depending on arguments', () => {
|
|
101
|
+
// see all possible matchers at
|
|
102
|
+
// https://sinonjs.org/releases/latest/matchers/
|
|
103
|
+
const greeter = {
|
|
104
|
+
/**
|
|
105
|
+
* Greets a person
|
|
106
|
+
* @param {string} name
|
|
107
|
+
*/
|
|
108
|
+
greet (name) {
|
|
109
|
+
return `Hello, ${name}!`
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
cy.stub(greeter, 'greet')
|
|
114
|
+
.callThrough() // if you want non-matched calls to call the real method
|
|
115
|
+
.withArgs(Cypress.sinon.match.string).returns('Hi')
|
|
116
|
+
.withArgs(Cypress.sinon.match.number).throws(new Error('Invalid name'))
|
|
117
|
+
|
|
118
|
+
expect(greeter.greet('World')).to.equal('Hi')
|
|
119
|
+
expect(() => greeter.greet(42)).to.throw('Invalid name')
|
|
120
|
+
expect(greeter.greet).to.have.been.calledTwice
|
|
121
|
+
|
|
122
|
+
// non-matched calls goes the actual method
|
|
123
|
+
expect(greeter.greet()).to.equal('Hello, undefined!')
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('matches call arguments using Sinon matchers', () => {
|
|
127
|
+
// see all possible matchers at
|
|
128
|
+
// https://sinonjs.org/releases/latest/matchers/
|
|
129
|
+
const calculator = {
|
|
130
|
+
/**
|
|
131
|
+
* returns the sum of two arguments
|
|
132
|
+
* @param a {number}
|
|
133
|
+
* @param b {number}
|
|
134
|
+
*/
|
|
135
|
+
add (a, b) {
|
|
136
|
+
return a + b
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const spy = cy.spy(calculator, 'add').as('add')
|
|
141
|
+
|
|
142
|
+
expect(calculator.add(2, 3)).to.equal(5)
|
|
143
|
+
|
|
144
|
+
// if we want to assert the exact values used during the call
|
|
145
|
+
expect(spy).to.be.calledWith(2, 3)
|
|
146
|
+
|
|
147
|
+
// let's confirm "add" method was called with two numbers
|
|
148
|
+
expect(spy).to.be.calledWith(Cypress.sinon.match.number, Cypress.sinon.match.number)
|
|
149
|
+
|
|
150
|
+
// alternatively, provide the value to match
|
|
151
|
+
expect(spy).to.be.calledWith(Cypress.sinon.match(2), Cypress.sinon.match(3))
|
|
152
|
+
|
|
153
|
+
// match any value
|
|
154
|
+
expect(spy).to.be.calledWith(Cypress.sinon.match.any, 3)
|
|
155
|
+
|
|
156
|
+
// match any value from a list
|
|
157
|
+
expect(spy).to.be.calledWith(Cypress.sinon.match.in([1, 2, 3]), 3)
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Returns true if the given number is even
|
|
161
|
+
* @param {number} x
|
|
162
|
+
*/
|
|
163
|
+
const isEven = (x) => x % 2 === 0
|
|
164
|
+
|
|
165
|
+
// expect the value to pass a custom predicate function
|
|
166
|
+
// the second argument to "sinon.match(predicate, message)" is
|
|
167
|
+
// shown if the predicate does not pass and assertion fails
|
|
168
|
+
expect(spy).to.be.calledWith(Cypress.sinon.match(isEven, 'isEven'), 3)
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Returns a function that checks if a given number is larger than the limit
|
|
172
|
+
* @param {number} limit
|
|
173
|
+
* @returns {(x: number) => boolean}
|
|
174
|
+
*/
|
|
175
|
+
const isGreaterThan = (limit) => (x) => x > limit
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Returns a function that checks if a given number is less than the limit
|
|
179
|
+
* @param {number} limit
|
|
180
|
+
* @returns {(x: number) => boolean}
|
|
181
|
+
*/
|
|
182
|
+
const isLessThan = (limit) => (x) => x < limit
|
|
183
|
+
|
|
184
|
+
// you can combine several matchers using "and", "or"
|
|
185
|
+
expect(spy).to.be.calledWith(
|
|
186
|
+
Cypress.sinon.match.number,
|
|
187
|
+
Cypress.sinon.match(isGreaterThan(2), '> 2').and(Cypress.sinon.match(isLessThan(4), '< 4')),
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
expect(spy).to.be.calledWith(
|
|
191
|
+
Cypress.sinon.match.number,
|
|
192
|
+
Cypress.sinon.match(isGreaterThan(200), '> 200').or(Cypress.sinon.match(3)),
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
// matchers can be used from BDD assertions
|
|
196
|
+
cy.get('@add').should('have.been.calledWith',
|
|
197
|
+
Cypress.sinon.match.number, Cypress.sinon.match(3))
|
|
198
|
+
|
|
199
|
+
// you can alias matchers for shorter test code
|
|
200
|
+
const { match: M } = Cypress.sinon
|
|
201
|
+
|
|
202
|
+
cy.get('@add').should('have.been.calledWith', M.number, M(3))
|
|
203
|
+
})
|
|
204
|
+
})
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
|
|
3
|
+
context('Local Storage / Session Storage', () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
cy.visit('https://example.cypress.io/commands/storage')
|
|
6
|
+
})
|
|
7
|
+
// Although localStorage is automatically cleared
|
|
8
|
+
// in between tests to maintain a clean state
|
|
9
|
+
// sometimes we need to clear localStorage manually
|
|
10
|
+
|
|
11
|
+
it('cy.clearLocalStorage() - clear all data in localStorage for the current origin', () => {
|
|
12
|
+
// https://on.cypress.io/clearlocalstorage
|
|
13
|
+
cy.get('.ls-btn').click()
|
|
14
|
+
cy.get('.ls-btn').should(() => {
|
|
15
|
+
expect(localStorage.getItem('prop1')).to.eq('red')
|
|
16
|
+
expect(localStorage.getItem('prop2')).to.eq('blue')
|
|
17
|
+
expect(localStorage.getItem('prop3')).to.eq('magenta')
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
cy.clearLocalStorage()
|
|
21
|
+
cy.getAllLocalStorage().should(() => {
|
|
22
|
+
expect(localStorage.getItem('prop1')).to.be.null
|
|
23
|
+
expect(localStorage.getItem('prop2')).to.be.null
|
|
24
|
+
expect(localStorage.getItem('prop3')).to.be.null
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
cy.get('.ls-btn').click()
|
|
28
|
+
cy.get('.ls-btn').should(() => {
|
|
29
|
+
expect(localStorage.getItem('prop1')).to.eq('red')
|
|
30
|
+
expect(localStorage.getItem('prop2')).to.eq('blue')
|
|
31
|
+
expect(localStorage.getItem('prop3')).to.eq('magenta')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// Clear key matching string in localStorage
|
|
35
|
+
cy.clearLocalStorage('prop1')
|
|
36
|
+
cy.getAllLocalStorage().should(() => {
|
|
37
|
+
expect(localStorage.getItem('prop1')).to.be.null
|
|
38
|
+
expect(localStorage.getItem('prop2')).to.eq('blue')
|
|
39
|
+
expect(localStorage.getItem('prop3')).to.eq('magenta')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
cy.get('.ls-btn').click()
|
|
43
|
+
cy.get('.ls-btn').should(() => {
|
|
44
|
+
expect(localStorage.getItem('prop1')).to.eq('red')
|
|
45
|
+
expect(localStorage.getItem('prop2')).to.eq('blue')
|
|
46
|
+
expect(localStorage.getItem('prop3')).to.eq('magenta')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// Clear keys matching regex in localStorage
|
|
50
|
+
cy.clearLocalStorage(/prop1|2/)
|
|
51
|
+
cy.getAllLocalStorage().should(() => {
|
|
52
|
+
expect(localStorage.getItem('prop1')).to.be.null
|
|
53
|
+
expect(localStorage.getItem('prop2')).to.be.null
|
|
54
|
+
expect(localStorage.getItem('prop3')).to.eq('magenta')
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('cy.getAllLocalStorage() - get all data in localStorage for all origins', () => {
|
|
59
|
+
// https://on.cypress.io/getalllocalstorage
|
|
60
|
+
cy.get('.ls-btn').click()
|
|
61
|
+
|
|
62
|
+
// getAllLocalStorage() yields a map of origins to localStorage values
|
|
63
|
+
cy.getAllLocalStorage().should((storageMap) => {
|
|
64
|
+
expect(storageMap).to.deep.equal({
|
|
65
|
+
// other origins will also be present if localStorage is set on them
|
|
66
|
+
'https://example.cypress.io': {
|
|
67
|
+
'prop1': 'red',
|
|
68
|
+
'prop2': 'blue',
|
|
69
|
+
'prop3': 'magenta',
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('cy.clearAllLocalStorage() - clear all data in localStorage for all origins', () => {
|
|
76
|
+
// https://on.cypress.io/clearalllocalstorage
|
|
77
|
+
cy.get('.ls-btn').click()
|
|
78
|
+
|
|
79
|
+
// clearAllLocalStorage() yields null
|
|
80
|
+
cy.clearAllLocalStorage()
|
|
81
|
+
cy.getAllLocalStorage().should(() => {
|
|
82
|
+
expect(localStorage.getItem('prop1')).to.be.null
|
|
83
|
+
expect(localStorage.getItem('prop2')).to.be.null
|
|
84
|
+
expect(localStorage.getItem('prop3')).to.be.null
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('cy.getAllSessionStorage() - get all data in sessionStorage for all origins', () => {
|
|
89
|
+
// https://on.cypress.io/getallsessionstorage
|
|
90
|
+
cy.get('.ls-btn').click()
|
|
91
|
+
|
|
92
|
+
// getAllSessionStorage() yields a map of origins to sessionStorage values
|
|
93
|
+
cy.getAllSessionStorage().should((storageMap) => {
|
|
94
|
+
expect(storageMap).to.deep.equal({
|
|
95
|
+
// other origins will also be present if sessionStorage is set on them
|
|
96
|
+
'https://example.cypress.io': {
|
|
97
|
+
'prop4': 'cyan',
|
|
98
|
+
'prop5': 'yellow',
|
|
99
|
+
'prop6': 'black',
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('cy.clearAllSessionStorage() - clear all data in sessionStorage for all origins', () => {
|
|
106
|
+
// https://on.cypress.io/clearallsessionstorage
|
|
107
|
+
cy.get('.ls-btn').click()
|
|
108
|
+
|
|
109
|
+
// clearAllSessionStorage() yields null
|
|
110
|
+
cy.clearAllSessionStorage()
|
|
111
|
+
cy.getAllSessionStorage().should(() => {
|
|
112
|
+
expect(sessionStorage.getItem('prop4')).to.be.null
|
|
113
|
+
expect(sessionStorage.getItem('prop5')).to.be.null
|
|
114
|
+
expect(sessionStorage.getItem('prop6')).to.be.null
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
})
|