我正在尝试为 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”
该方法本身有效,所以我不明白为什么测试失败。非常感谢任何建议