File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,38 @@ The fixture file should be an array of items.
4040
4141See [todos.cy.js](./cypress/e2e/todos.cy.js) and [todos.json](./cypress/fixtures/todos.json) for examples
4242
43+ The mocks and data are reset before each test.
44+
45+ ### data access
46+
47+ You can get the "live" data for each resource by name, for example
48+
49+ ` ` ` js
50+ it (' adds a todo' , { rest: { todos: ' todos.json' } }, () => {
51+ // use the REST resource name
52+ const todos = Cypress .env (' todos' )
53+ const n = todos .length
54+ cy .visit (' /' )
55+ cy .get (' li.todo' ).should (' have.length' , n)
56+ cy .get (' input.new-todo' )
57+ .type (' Write tests{enter}' )
58+ // there should be one more item in the array
59+ .then (() => {
60+ expect (todos).to .have .length (n + 1 )
61+ })
62+ })
63+ ` ` `
64+
65+ You need ` cy .then ` to access the changed data _after_ Cypress commands have finished. Alternatively, you can wrap the array reference:
66+
67+ ` ` ` js
68+ cy .get (' input.new-todo' )
69+ .type (' Write tests{enter}' )
70+ // there should be one more item in the array
71+ cy .wrap (todos)
72+ .should (' have.length' , n + 1 )
73+ ` ` `
74+
4375### baseUrl
4476
4577If all your REST endpoints use the same prefix, you can set the ` baseUrl` option
You can’t perform that action at this time.
0 commit comments