2

Atom.io エディター用の単純なパッケージを作成しようとしています。これは、Coffeescript を使用した初めての経験です。だから私はおそらく些細なことを見逃しています。

とにかく、これは私のindex.coffeeです。

module.exports =
 activate: ->
   atom.workspaceView.command "md-utils:unorderedList", => @unorderedList()
 unorderedList: ->
   out = ""
   editor = atom.workspace.activePaneItem
   selection = editor.getSelection()
   lines = selection.getText().split "\n"
   for line in lines
   out += "- " + line + "\n"
   console.log(lines)
   selection.insertText(out)

そして、ここに私の index-spec.coffee があります

{WorkspaceView} = require 'atom'

    describe "Markdown Utilities", ->
      [editor, editorView] = []

      unorderedList = (callback) ->
        editorView.trigger "md-utils:unorderedList"
        runs(callback)


      beforeEach ->

        atom.workspaceView = new WorkspaceView
        atom.workspaceView.openSync()

        editorView = atom.workspaceView.getActiveView()
        editor = editorView.getEditor()

      describe "when text is selected", ->
        it "formats it correctly", ->
          console.log = jasmine.createSpy("log")
          editor.setText """
            a
            b
            c
            d
          """
          editor.selectAll()
          unorderedList ->
            expect(console.log).toHaveBeenCalled()
            expect(editor.getText()).toBe """
            - a
            - b
            - c
            - d
          """

今、仕様を実行すると、index.coffee のメソッドが呼び出されていないように見えます。両方の期待が失敗しました:

  • スパイ ログが呼び出されたはずです。
  • 「abc d」は「-a -b -c -d」である必要があります

メソッド自体は機能するため、テストが失敗する理由がわかりません。どんな提案でも大歓迎です

4

1 に答える 1