简体   繁体   English

摩卡咖啡描述“意外的字符串错误”

[英]mocha describe 'unexpected string error'

I am writing the below test cases using Mocha in node.js. 我在node.js中使用Mocha编写以下测试用例。 Please find the below code : 请找到以下代码:

describe('Car', function() { describe('Car',function(){

it('can park?',function() 它(“可以停车吗?”,功能()

{ const car = new Car(); {const car = new Car(); assert.equal(car.park(),'stopped'); assert.equal(car.park(),'stopped'); }); }); }); });

I am running this using following command : 我正在使用以下命令运行此命令:

npm run test

It populates following error : 它填充以下错误:

> inbox@1.0.0 test /Users/abc/test/
> mocha

/Users/abc/test/Inbox.test.js:18
describe('Car', function() {
     ^^^^^

SyntaxError: Unexpected string
at new Script (vm.js:74:7)
at createScript (vm.js:246:10)
at Object.runInThisContext (vm.js:298:10)
at Module._compile (internal/modules/cjs/loader.js:670:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)

Can you please help me, what i am doing wrong here? 您能帮我吗,我在这里做错了吗?

Note : package.json is also updated with mocha in scripts field. 注意:package.json也将在脚本字段中用mocha更新。

I know i am answering to my own question but its more like recording it for others. 我知道我在回答自己的问题,但更像是为他人录制。

Just Use following statement in your code at top or before describe statements 只需在代码顶部或以下描述语句中使用以下语句

"use strict"; “使用严格”;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM