angular-cli: ng test - TypeError: (msg || "").replace is not a function
When you generate new project with ‘ng new’ and immediately run tests - they work. But when going a bit further and adding some dependencies (like jQuery, Bootstrap 4 and Trumbowyg) tests starts to fail right away with TypeError: (msg || “”).replace is not a function. Here’s the output:
10 05 2016 04:19:17.581:WARN [karma]: No captured browser, open http://localhost:9876/
10 05 2016 04:19:17.595:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
10 05 2016 04:19:17.600:INFO [launcher]: Starting browser Chrome
10 05 2016 04:19:18.359:INFO [Chrome 50.0.2661 (Windows 10 0.0.0)]: Connected on socket /#-kPxpXeuzKFiXoPcAAAA with id 7707656
Missing error handler on `socket`.
TypeError: (msg || "").replace is not a function
at D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\lib\reporter.js:45:23
at onBrowserError (D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\lib\reporters\base.js:58:60)
at null.<anonymous> (D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\lib\events.js:13:22)
at emitTwo (events.js:100:13)
at emit (events.js:185:7)
at onKarmaError (D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\lib\browser.js:95:13)
at Socket.<anonymous> (D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\lib\events.js:13:22)
at emitOne (events.js:95:20)
at Socket.emit (events.js:182:7)
at Socket.onevent (D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\node_modules\socket.io\lib\socket.js:335:8)
at Socket.onpacket (D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\node_modules\socket.io\lib\socket.js:295:12)
at Client.ondecoded (D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\node_modules\socket.io\lib\client.js:193:14)
at Decoder.Emitter.emit (D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\node_modules\socket.io\node_modules\socket.io-parser\node_modules\component-emitter\index.js:134:20)
at Decoder.add (D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\node_modules\socket.io\node_modules\socket.io-parser\index.js:247:12)
at Client.ondata (D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\node_modules\socket.io\lib\client.js:175:18)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at Socket.onPacket (D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\node_modules\socket.io\node_modules\engine.io\lib\socket.js:101:14)
at emitOne (events.js:90:13)
at WebSocket.emit (events.js:182:7)
at WebSocket.Transport.onPacket (D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\node_modules\socket.io\node_modules\engine.io\lib\transport.js:104:8)
at WebSocket.Transport.onData (D:\Documents\Visual Studio 2015\Projects\TestAppCLI\node_modules\karma\node_modules\socket.io\node_modules\engine.io\lib\transport.js:115:8)
10 05 2016 04:19:21.367:WARN [Chrome 50.0.2661 (Windows 10 0.0.0)]: Disconnected (1 times)
Does anyone know how to fix it? It’s really annoying. I already tried to recreate project from scratch, step-by-step => no luck 😦
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 26 (8 by maintainers)
I am also receiving this error using CLI version 1.0.0-beta.9. Haven’t tried beta.10 yet.
It only happens when I try to return a mocked Observable like this:
When I comment out the return block all is well.
Here’s the error for reference:
When I’ve had this problem, it has meant that there was a TypeScript compilation error someplace else in the code. So, once I fixed all of the errors, the problem went away.
This error is unhelpful because it hides the actual problem, but perhaps you’ll be fine if there are other errors that you can clean up.
I got the similar error when Angular CLI is upgraded to 1.0.0-beta.11-webpack.2 and @angular2-material to 2.0.0-alpha.7-4, when run
ng test
in the command line, and got the following info.Thanks, but that didn’t help. Same error.
We came across this very issue as well.
We fixed it by adding symbol-observable dependency: