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.

Import a function throws type error exception

See original GitHub issue

Current behavior:

Importing a function from a diferent file throws a type error

Test code to reproduce

I want to test a page wich uses basic auth. So I write this line on a test:

cy.visit("/my_url", { auth:{
      username: Cypress.env("BASICAUTH_USERNAME"),
      password: Cypress.env("BASICAUTH_USERNAME")
    } });

This line works with no problem. However, I want to test other pages with basic auth too. So, in order to avoid repeating this object I made a function to retrieve it:

//Auth.js"
export default {
  basicAuth: () => {
    return {
      username: Cypress.env("BASICAUTH_USERNAME"),
      password: Cypress.env("BASICAUTH_USERNAME")
    };
  }
};

Then I import it on my original test file:

import { basicAuth } from "./Auth";

//other lines here:

cy.visit("/my_url", { auth:basicAuth() });

Then when I run the code, I get a Type error on console:

> TypeError: Auth_1.basicAuth is not a function
      at xxxxxxx (#URL-Here#/__cypress/tests?p=test/app.spec.js-193:74:26)
      at Context.<anonymous> (#URL-Here#/__cypress/tests?p=test/app.spec.js-193:29:13)

Versions

Cypress/included:4.4.0 from https://github.com/cypress-io/cypress-docker-images

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sainthkhcommented, Apr 17, 2020

I’ll check it out.

0reactions
cypress-bot[bot]commented, Apr 20, 2020

Released in 4.4.1.

This comment thread has been locked. If you are still experiencing this issue after upgrading to Cypress v4.4.1, please open a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Built-in Exceptions — Python 3.11.1 documentation
Except where mentioned, they have an “associated value” indicating the detailed cause of the error. This may be a string or a tuple...
Read more >
How to declare a function that throws an error in Typescript
It's possible to specify error type only if a function returns an error, not throws it (this rarely happens and is prone to...
Read more >
How to Throw Exceptions in Python - Rollbar
Python throws the TypeError exception when there are wrong data types. Similar to TypeError, there are several built-in exceptions like:.
Read more >
throw - JavaScript - MDN Web Docs - Mozilla
The throw statement throws a user-defined exception. ... If no catch block exists among caller functions, the program will terminate.
Read more >
How to throw an exception - Python Morsels
The sqrt function in Python's math module raises an exception when it's given a negative ... and we'll raise a TypeError exception if...
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