https://cypress.io logo
Join Discord
Powered by
# help
  • s

    stocky-dream-36427

    05/14/2021, 4:11 PM
    but I wouldn't recommend it because it's annoying to maintain
  • b

    breezy-australia-64868

    05/14/2021, 4:11 PM
    Cool, I like that! So if my
    actions.js
    file is importing my
    ./api.js
    , is there a way I can mock that file?
  • b

    breezy-australia-64868

    05/14/2021, 4:11 PM
    Ah gotcha
  • s

    stocky-dream-36427

    05/14/2021, 4:11 PM
    You can, but I wouldn't recommend it. I'd do it on the network level and you can control pass/failure/error/invalid responses at an app level
  • b

    breezy-australia-64868

    05/14/2021, 4:12 PM
    With something like
    cy.intercept
    ?
  • s

    stocky-dream-36427

    05/14/2021, 4:12 PM
    Yerp
  • b

    breezy-australia-64868

    05/14/2021, 4:12 PM
    Got it. I use Firebase for this project and I've found it a little bit confusing to intercept those requests since they're often live data and websockets, but I'll give that a try!
  • s

    stocky-dream-36427

    05/14/2021, 4:13 PM
    Got it. Yeah I can see why that's weird.
  • s

    stocky-dream-36427

    05/14/2021, 4:13 PM
    Lemme show you how to file mock.
  • b

    breezy-australia-64868

    05/14/2021, 4:13 PM
    Awesome 🙂
  • s

    stocky-dream-36427

    05/14/2021, 4:13 PM
    It can be awkward because you can't mock destructured objects
  • s

    stocky-dream-36427

    05/14/2021, 4:14 PM
    So you may need to export the entire module instead of the destructured version (in your tests)
  • b

    breezy-australia-64868

    05/14/2021, 4:14 PM
    Gotcha
  • s

    stocky-dream-36427

    05/14/2021, 4:14 PM
    This is a node limitation. You are also able to mock files if you do it at the webpack level, but I generally find that it's ok to make the destructure => object change
  • s

    stocky-dream-36427

    05/14/2021, 4:15 PM
    lemme send u a file
  • b

    breezy-australia-64868

    05/14/2021, 4:15 PM
    Yeah that seems like the way I'd prefer it too
  • b

    breezy-australia-64868

    05/14/2021, 4:15 PM
    thx!
  • s

    stocky-dream-36427

    05/14/2021, 4:16 PM
    https://github.com/cypress-io/cypress/tree/develop/npm/vue/cypress/component/advanced/mocking-axios
  • s

    stocky-dream-36427

    05/14/2021, 4:16 PM
    https://github.com/cypress-io/cypress/tree/develop/npm/vue/cypress/component/counter-vuex
  • s

    stocky-dream-36427

    05/14/2021, 4:17 PM
    (The axios mock is an example of a file-level mock)
  • s

    stocky-dream-36427

    05/14/2021, 4:18 PM
    you can do the same with your api.
  • b

    breezy-australia-64868

    05/14/2021, 4:18 PM
    sweet, ill look at that. thanks so much!
  • u

    user

    05/14/2021, 9:43 PM
    is lmiller1990 here? i'm the guy on https://github.com/cypress-io/cypress/pull/16504
  • u

    user

    05/14/2021, 10:04 PM
    Hi Jess, thank you for you support. Ok, I got it. I was accessing the store inspired by this post at cypress blog https://www.cypress.io/blog/2017/11/28/testing-vue-web-application-with-vuex-data-store-and-rest-backend/#store-testing. Yeah, I was thinking this kind of error is common for this approach or something like that. I am refactoring here just trying to not access store directly after all I am build E2E tests.
  • b

    bulky-sundown-74498

    05/14/2021, 10:06 PM
    @User you could also use component testing on a smaller scale to test your components in isolation. In this case it woudl be easier for you to mock the store and all the dependencies of the context.
  • u

    user

    05/14/2021, 10:15 PM
    Oh, yeah, for sure. Thank you for the tip @User! I have seen a little bit cypress's docs for component tests. I'll focus more there...
  • u

    user

    05/15/2021, 1:15 AM
    Copy code
    0 passing (324ms)
      1 failing
    
      1) An uncaught error was detected outside of a test:
         ReferenceError: The following error originated from your test code, not from Cypress.
    
      > process is not defined
    
    When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
    
    Cypress could not associate this error to any specific test.
    
    We dynamically generated a new test to display this failure.
          at Object../node_modules/variable-diff/node_modules/supports-color/index.js (https://localhost:6080/__cypress/tests?p=cypress/support/index.js:53491:12)
          at __webpack_require__ (https://localhost:6080/__cypress/tests?p=cypress/support/index.js:53660:42)
          at Object../node_modules/variable-diff/node_modules/chalk/index.js (https://localhost:6080/__cypress/tests?p=cypress/support/index.js:53351:21)
          at __webpack_require__ (https://localhost:6080/__cypress/tests?p=cypress/support/index.js:53660:42)
          at Object../node_modules/variable-diff/index.js (https://localhost:6080/__cypress/tests?p=cypress/support/index.js:53114:13)
          at __webpack_require__ (https://localhost:6080/__cypress/tests?p=cypress/support/index.js:53660:42)
          at Object../node_modules/snap-shot-compare/src/index.js (https://localhost:6080/__cypress/tests?p=cypress/support/index.js:42534:14)
          at __webpack_require__ (https://localhost:6080/__cypress/tests?p=cypress/support/index.js:53660:42)
          at Object../node_modules/@cypress/snapshot/src/index.js (https://localhost:6080/__cypress/tests?p=cypress/support/index.js:18:17)
          at __webpack_require__ (https://localhost:6080/__cypress/tests?p=cypress/support/index.js:53660:42)
  • u

    user

    05/15/2021, 1:15 AM
    how can i find where that is?
  • u

    user

    05/15/2021, 1:20 AM
    this stack trace suggests that cypress itself is faulty?
  • c

    crooked-television-64942

    05/17/2021, 7:23 AM
    Hey peeps 👋 I was very excited about this lib from @User for test tagging https://github.com/bahmutov/cypress-grep but unfortunately it is not working for my project 🤔 when I run this command:
    Copy code
    sh
    npx cypress run --env grepTags=smoke
    it outputs
    cypress-grep: filtering using tag "smoke"
    in the terminal, but all tests run. Has anyone setup this lib and had success?
1...101112...252Latest