そのため、express.js プロジェクトで BDD とモカをいじっています。私は始めたばかりなので、最初のテストケースとして持っているものは次のとおりです。
should = require "should"
require "../lib/models/skill.js"
describe 'Skill', ->
describe '#constructor()', ->
it 'should return an instance of class skill', ->
testSkill = new Skill "iOS", "4 years", 100
testSkill.constructor.name.should.equal 'Skill'
(また、この coffeescript は、最後のステートメントに return を挿入するため、奇妙な見た目の js を生成します。これは、coffeescript を使用してテストをセットアップする正しい方法ですか?)
mocha を実行すると、次のエラーが表示されます。
1) Skill #constructor() should return an instance of class skill:
ReferenceError: Skill is not defined
これは、skill.js が正しくインポートされなかったことを意味します。この時点で私のスキル クラスは非常に単純で、単なるコンストラクターです。
class Skill
constructor: (@name,@years,@width) ->
mocha テストがモデルにアクセスできるようにモデルをインポートするにはどうすればよいですか?