Jest: TypeError: string.replace is not a function

Created on 1 Sep 2016  Â·  12Comments  Â·  Source: facebook/jest

Do you want to request a _feature_ or report a _bug_?

Bug; updating from 0.1.40 to 15.0.2.

What is the current behavior?

Running jest gives me:

TypeError: string.replace is not a function
    at string (C:\xampp\htdocs\outlandish\kasia\node_modules\jest-util\build\index.js:44:19)
    at p (C:\xampp\htdocs\outlandish\kasia\node_modules\jest-cli\build\SearchSource.js:63:26)
    at new SearchSource (C:\xampp\htdocs\outlandish\kasia\node_modules\jest-cli\build\SearchSource.js:97:34)
    at C:\xampp\htdocs\outlandish\kasia\node_modules\jest-cli\build\jest.js:139:20
    at process._tickCallback (node.js:412:9)

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal repository on GitHub that we can npm install and npm test.

Not sure what the problem is and therefore am not sure I could reliably reproduce it.

Run Jest again with --debug and provide the full configuration it prints. Please mention your node and npm version and operating system.

Node: 5.9.1
npm: 3.8.3

jest version = 15.0.2                                                                                              
test framework = jasmine2                                                                                          
config = {                                                                                                         
  "automock": true,                                                                                                
  "verbose": true,                                                                                                 
  "testRegex": [                                                                                                   
    "/test/.*\\.js$"                                                                                               
  ],                                                                                                               
  "unmockedModulePathPatterns": [                                                                                  
    "C:\\\\xampp\\\\htdocs\\\\outlandish\\\\kasia\\\\node_modules\\\\react",                                       
    "C:\\\\xampp\\\\htdocs\\\\outlandish\\\\kasia\\\\node_modules\\\\react-dom",                                   
    "C:\\\\xampp\\\\htdocs\\\\outlandish\\\\kasia\\\\node_modules\\\\react-addons-test-utils",                     
    "C:\\\\xampp\\\\htdocs\\\\outlandish\\\\kasia\\\\node_modules\\\\enzyme",                                      
    "C:\\\\xampp\\\\htdocs\\\\outlandish\\\\kasia\\\\node_modules\\\\lodash"                                       
  ],                                                                                                               
  "testPathIgnorePatterns": [                                                                                      
    "\\\\node_modules\\\\",                                                                                        
    "\\\\fixtures\\\\",                                                                                            
    "\\\\components\\\\"                                                                                           
  ],                                                                                                               
  "rootDir": "C:\\xampp\\htdocs\\outlandish\\kasia",                                                               
  "name": "C:-xampp-htdocs-outlandish-kasia",                                                                      
  "setupFiles": [                                                                                                  
    "C:\\xampp\\htdocs\\outlandish\\kasia\\node_modules\\babel-polyfill\\lib\\index.js"                            
  ],                                                                                                               
  "testRunner": "C:\\xampp\\htdocs\\outlandish\\kasia\\node_modules\\jest-jasmine2\\build\\index.js",              
  "scriptPreprocessor": "C:\\xampp\\htdocs\\outlandish\\kasia\\node_modules\\babel-jest\\src\\index.js",           
  "usesBabelJest": true,                                                                                           
  "preprocessorIgnorePatterns": [                                                                                  
    "\\\\node_modules\\\\"                                                                                         
  ],                                                                                                               
  "bail": false,                                                                                                   
  "browser": false,                                                                                                
  "cacheDirectory": "C:\\Users\\SAMIAM~1\\AppData\\Local\\Temp\\jest",                                             
  "colors": false,                                                                                                 
  "coveragePathIgnorePatterns": [                                                                                  
    "\\\\node_modules\\\\"                                                                                         
  ],                                                                                                               
  "coverageReporters": [                                                                                           
    "json",                                                                                                        
    "text",                                                                                                        
    "lcov",                                                                                                        
    "clover"                                                                                                       
  ],                                                                                                               
  "globals": {},                                                                                                   
  "haste": {                                                                                                       
    "providesModuleNodeModules": []                                                                                
  },                                                                                                               
  "mocksPattern": "__mocks__",                                                                                     
  "moduleDirectories": [                                                                                           
    "node_modules"                                                                                                 
  ],                                                                                                               
  "moduleFileExtensions": [                                                                                        
    "js",                                                                                                          
    "json",                                                                                                        
    "node"                                                                                                         
  ],                                                                                                               
  "moduleNameMapper": {},                                                                                          
  "modulePathIgnorePatterns": [],                                                                                  
  "noStackTrace": false,                                                                                           
  "notify": false,                                                                                                 
  "preset": null,                                                                                                  
  "resetModules": false,                                                                                           
  "testEnvironment": "jest-environment-jsdom",                                                                     
  "testPathDirs": [                                                                                                
    "C:\\xampp\\htdocs\\outlandish\\kasia"                                                                         
  ],                                                                                                               
  "testURL": "about:blank",                                                                                        
  "timers": "real",                                                                                                
  "useStderr": false,                                                                                              
  "watch": false,                                                                                                  
  "cache": true,                                                                                                   
  "watchman": true,                                                                                                
  "testcheckOptions": {                                                                                            
    "times": 100,                                                                                                  
    "maxSize": 200                                                                                                 
  }                                                                                                                
}                                                                                                                  

Most helpful comment

but.. they are JavaScript responses, not swift.

All 12 comments

Wait, are you really upgrading from 0.1.40 or do you mean 14.0?

@cpojer 0.1.40 :-)

Woah! Can you create a minimal repro and put it up on GitHub? I'm going to fix some Windows issues in Jest today and could take a look then.

@cpojer Bit tight for time at the moment, but I will try. Would a minimal repro consist of just a no-op test with the config that I am using?

Oops, wrong button!

yeah, as long as it shows the same issue on Windows and I can easily "npm install" and "npm test" it.

@cpojer Ok that was much quicker than I expected! Here ya go.

Aha! I found the problem. I was passing an array to the testRegex option. :disappointed:

Would a PR for checking the type of this option be desirable?

Yeah, adding validation to this is definitely nice – appreciate any PRs you could send :)

Closing this issue because it isn't a bug.

@cpojer Great, I'll see what I can cook up. Thanks for your swift responses!

but.. they are JavaScript responses, not swift.

dateFormatChanger = dateFormatChanger.replace(/d|D/, "DD");

I still get error
TypeError: dateFormatChanger.replace is not a function

Was this page helpful?
0 / 5 - 0 ratings