question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'replace' of undefined" at Object.appendErrMsg

See original GitHub issue

Current behavior:

This is a weird issue that is isolated to a single machine.

If I try run a test file with more than one or two tests, I get the following: screen shot 2018-05-03 at 10 59 12 am

The stack trace:

TypeError: Cannot read property 'replace' of undefined

Because this error occurred during a 'before each' hook we are skipping the remaining tests in the current suite: 'bulk actions'
    at Object.appendErrMsg (http://localhost:3000/__cypress/runner/cypress_runner.js:66723:23)
    at Runner.<anonymous> (http://localhost:3000/__cypress/runner/cypress_runner.js:65768:20)
    at Runner.EventEmitter.emit (http://localhost:3000/__cypress/runner/cypress_runner.js:28665:13)
    at Runner.fail (http://localhost:3000/__cypress/runner/cypress_runner.js:65066:17)
    at Runner.failHook (http://localhost:3000/__cypress/runner/cypress_runner.js:33083:8)
    at http://localhost:3000/__cypress/runner/cypress_runner.js:33128:16
    at http://localhost:3000/__cypress/runner/cypress_runner.js:65918:11
From previous event:
    at onNext (http://localhost:3000/__cypress/runner/cypress_runner.js:65917:57)
    at done (http://localhost:3000/__cypress/runner/cypress_runner.js:32741:5)
    at Hook.Runnable.run (http://localhost:3000/__cypress/runner/cypress_runner.js:32776:5)
    at http://localhost:3000/__cypress/runner/cypress_runner.js:65936:28
From previous event:
    at Object.onRunnableRun (http://localhost:3000/__cypress/runner/cypress_runner.js:65935:20)
    at $Cypress.action (http://localhost:3000/__cypress/runner/cypress_runner.js:61399:51)
    at Hook.Runnable.run (http://localhost:3000/__cypress/runner/cypress_runner.js:65075:20)
    at next (http://localhost:3000/__cypress/runner/cypress_runner.js:33119:10)
    at http://localhost:3000/__cypress/runner/cypress_runner.js:33141:5
    at timeslice (http://localhost:3000/__cypress/runner/cypress_runner.js:28382:27)

The test spec file like:

describe('tests', () => {
  beforeEach(() => {
    cy.authenticatedVisit(
      'some_url'
    )
  })
  it('draws a box', () => {})
  it('potato', () => {})
  it('draws a circle', () => {})
  it('draws nothing', () => {})
})

and the authenticatedVisit command is:

Cypress.Commands.add('authenticatedVisit', url => {
  cy.visit(url, {
    onBeforeLoad() {
      window.localStorage.setItem(
        'authRefreshToken',
        userJames.authRefreshToken
      )
      window.localStorage.setItem('authAccessToken', null) //it needs this field to have an entry
    },
  })
})

It works perfectly fine on other machines with the exact same set up.

It works fine running a single test at a time - but I’m wondering if anyone else has experienced this before?

Happy to provide any extra info if I can!

Versions

Both cypress 2.1.0 and the previous version. Mac OS 10.13.4, chrome 66.0.3359.139

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
eddifcommented, Jun 11, 2019

Similar to @echurilov I’m unable to call cy.setCookie() within a beforeEach:

image

Within the Cypress window I see the error TypeError: Cannot read property ‘replace’ of undefined -

image

2reactions
echurilovcommented, Mar 7, 2019

I’m getting a similar error in 3.1.5 when trying to cy.setCookie in a before: TypeError: Cannot read property 'replace' of undefined" at Object.appendErrMsg

Inserting that on-fail debugger as you showed yields err = Error and runnable.trace.message = "Error: done() called multiple times" at Hook.Runnable

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'replace' of undefined
I have been trying to make my first express application and I have been getting a error with range.replace() ...
Read more >
TypeError: Cannot read property 'replace' of undefined
but I get the error “TypeError: Cannot read property 'replace' of undefined” when I do this: const img_url = resultTitle.attr("src").replace(" ...
Read more >
[SOLVED] Cannot Read Property 'replace' of Undefined in JS
This error occurs when you attempt to call the replace() method on a variable that has a value of undefined . const str...
Read more >
Cannot read property 'replace' of undefined error
Hi everyone, I am trying to run the GetStream/stream-nodejs example app of getStream.io . But I am facing the following error. var STREAM_URL...
Read more >
TypeError: Cannot read property 'replace' of undefined
Issue Description Not able to upload package in ORchestrator Production server - Receiving error “TypeError: Cannot read property 'replace' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found