Cypress is failed when calling new user-defined function
See original GitHub issueCurrent behavior:
I created a new file that defined all functions which will be used for my module. When I created new spec and called it, Cypress showed the error like XXX is not a function. However, if I put that function into the command and it worked as normal. I also tried to delete the cache, reinstall Cypress but it is not working properly.
Desired behavior:
New function should be called and working properly.
Steps to reproduce:
- Create new file, e.g.
plan.jsand put it under support folder - Declare the function, e.g.
Createnewplanas below
Cypress.Commands.add('createNewPlan', (planType, planName) => {
// Put your source code here
})
- Go to integration folder then create a spec file, e.g. plan_spec.js
- In the spec file, put the function as the below code
describe('Plan List page', function() {
it('Create new plan', function() {
const user = this.users[0]
const planList = this.planLists[0]
cy.login(user.username, user.password)
// Create new plan
cy.createNewPlan(planList.planType, planList.planName)
})
- At the runtime, Cypress shows the error
TypeError: cy.createNewPlan is not a function

Versions
Cypress version: 3.1.1 OS: Win 10 Browser: Chrome 70
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Cypress custom command is not recognized when invoked
I'm invoking it in my spec with cy.login(testuser, testpwd) , but I'm getting the following error message: TypeError: cy.login is not a function...
Read more >Error Messages | Cypress Documentation
This message means that Cypress was unable to find tests in the specified file. You'll likely get this message if you have an...
Read more >Custom Commands - Cypress Documentation
Cypress comes with its own API for creating custom commands and overwriting existing commands. The built in Cypress commands use the very same...
Read more >Test Retries - Cypress Documentation
If the test fails a third time, Cypress will mark the test as failed and then move on to run any remaining tests....
Read more >Best Practices - Cypress Documentation
The Real World App (RWA) uses two useful custom commands for selecting elements ... If the content of the element changed would you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Files in
cypress/supportare not all automatically loaded. Onlycypress/support/index.jsis loaded. If you look at it, you’ll see its contents include something like:If you create
cypress/support/plan.js, you need to import it incypress/support/index.js:As mentioned above you get this error if you convert your
support/index.jsto Typescript without telling Cypress to look for a TS support file.Add this to your
cypress.jsonfile:"supportFile": "./cypress/support/index.ts"