Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server XHR is not detected / stubbed when using document.write #1139

Closed
bahmutov opened this issue Dec 31, 2017 · 6 comments
Closed

Server XHR is not detected / stubbed when using document.write #1139

bahmutov opened this issue Dec 31, 2017 · 6 comments
Labels
pkg/https-proxy This is due to an issue in the packages/https-proxy directory type: bug

Comments

@bahmutov
Copy link
Contributor

Cypress 1.4.x

If we do NOT use cy.visit to open a page, and just do document.write, then the XHR requests are not detected and are not stubbed.

Example: https://github.com/bahmutov/cypress-hyperapp-unit-test/blob/master/cypress/integration/server-todos-spec.js#L8 where I stub the server XHR route before mounting a Hyperapp component. Same stubbing works if we do not mount Hyperapp but just load an HTML page. In this example, the command log does not even show XHR

screen shot 2017-12-30 at 11 27 05 pm

@bahmutov bahmutov added pkg/https-proxy This is due to an issue in the packages/https-proxy directory type: bug labels Dec 31, 2017
@bahmutov
Copy link
Contributor Author

bahmutov commented Dec 31, 2017

The test stubs the route, mounts the component, then expects to find the synthetic data

  cy.server()
    cy.route('/todos?_limit=3', mockTodos)
  })

  context('Stubbed server', () => {
    beforeEach(() => {
      const state = {
        todos: []
      }
      const actions = {
        setTodos: todos => state => ({ todos }),
        toggle
      }
      const view = (state, actions) =>
        h(ServerTodos, {
          n: 3,
          todosLoaded: actions.setTodos,
          todos: state.todos,
          toggle: actions.toggle
        })
      mount(state, actions, view)
    })

    // skip until can figure out why the server is not stubbed
    // when writing into document directly.
    it.skip('shows todos', () => {
      cy.contains('Todo')
      cy.get('.todo').should('have.length', 3)
      cy.get('.todo').first().contains('Stub server')
    })

@brian-mann
Copy link
Member

We don't bind to the remote app before the first cy.visit so we just need to add the bindings immediately when the remote window is first created.

@bahmutov
Copy link
Contributor Author

bahmutov commented Dec 31, 2017 via email

@brian-mann
Copy link
Member

brian-mann commented Dec 31, 2017

I see now. You are initiating the XHR from the spec frame - not the app frame. The test frame is not bound to - although we could do that as well.

@bahmutov
Copy link
Contributor Author

bahmutov commented Dec 31, 2017 via email

@jennifer-shehane
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg/https-proxy This is due to an issue in the packages/https-proxy directory type: bug
Projects
None yet
Development

No branches or pull requests

3 participants