Coffeescript 如何与atom软件包规范中的确认对话框交互? 问题
对于涉及到与atom编辑器确认对话框交互的代码,我必须编写规范,有哪些选项 出身背景 我正在为atom开发一个包,并有一个删除文件的命令,然后将更改推送到服务器。我想编写一个测试来验证命令的行为,但是我很难找到一个好方法来模拟单击确认对话框上的取消/确定按钮 命令代码如下所示Coffeescript 如何与atom软件包规范中的确认对话框交互? 问题,coffeescript,tdd,jasmine,jasmine-node,atom-editor,Coffeescript,Tdd,Jasmine,Jasmine Node,Atom Editor,对于涉及到与atom编辑器确认对话框交互的代码,我必须编写规范,有哪些选项 出身背景 我正在为atom开发一个包,并有一个删除文件的命令,然后将更改推送到服务器。我想编写一个测试来验证命令的行为,但是我很难找到一个好方法来模拟单击确认对话框上的取消/确定按钮 命令代码如下所示 atom.workspaceView.command "mavensmate:delete-file-from-server", => # do setup stuff (build the params obj
atom.workspaceView.command "mavensmate:delete-file-from-server", =>
# do setup stuff (build the params object)
atom.confirm
message: "You sure?"
buttons:
Cancel: => # nothing to do here, just let the window close
Delete: => # run the delete handler
@mm.run(params).then (result) =>
@mmResponseHandler(params, result)
atom.workspaceView.command "mavensmate:delete-file-from-server", =>
# do setup stuff (build the params object)
atom.confirm
message: "You sure?"
buttons: ["Cancel", "Delete"]
if answer == 1
@mm.run(params).then (result) =>
@mmResponseHandler(params, result)
我似乎不知道如何让cancel或delete回调在规范中运行。我一直在挖掘所有atom规范并搜索google,但似乎什么都没有出现。我本来希望将返回设置为我想要触发的回调的索引会起作用,但是我的delete按钮回调永远不会被调用
# Delete the metadata in the active pane from the server
describe 'Delete File from Server', ->
filePath = ''
beforeEach ->
# set up the workspace with a fake apex class
directory = temp.mkdirSync()
atom.project.setPath(directory)
filePath = path.join(directory, 'MyClass.cls')
spyOn(mm, 'run').andCallThrough()
waitsForPromise ->
atom.workspace.open(filePath)
it 'should invoke mavensmate:delete-file-from-server if confirmed', ->
spyOn(atom, 'confirm').andReturn(1)
atom.workspaceView.trigger 'mavensmate:delete-file-from-server'
expect(mm.run).toHaveBeenCalled()
# Delete the metadata in the active pane from the server
describe 'Delete File from Server', ->
filePath = ''
beforeEach ->
# set up the workspace with a fake apex class
directory = temp.mkdirSync()
atom.project.setPath(directory)
filePath = path.join(directory, 'MyClass.cls')
spyOn(mm, 'run').andCallThrough()
waitsForPromise ->
atom.workspace.open(filePath)
it 'should invoke mavensmate:delete-file-from-server if confirmed', ->
spyOn(atom, 'confirm').andReturn(1)
atom.workspaceView.trigger 'mavensmate:delete-file-from-server'
expect(mm.run).toHaveBeenCalled()
有没有更好的方法来模拟用户单击确认对话框上的按钮?有什么解决办法可以测试这个问题吗?如果您用按钮传入回调,那么模拟与确认对话框的交互似乎不是一个好方法,但是如果您只是传递了一个数组,并让命令触发器响应该数组,那么您可以根据需要编写规范 命令代码将如下所示
atom.workspaceView.command "mavensmate:delete-file-from-server", =>
# do setup stuff (build the params object)
atom.confirm
message: "You sure?"
buttons:
Cancel: => # nothing to do here, just let the window close
Delete: => # run the delete handler
@mm.run(params).then (result) =>
@mmResponseHandler(params, result)
atom.workspaceView.command "mavensmate:delete-file-from-server", =>
# do setup stuff (build the params object)
atom.confirm
message: "You sure?"
buttons: ["Cancel", "Delete"]
if answer == 1
@mm.run(params).then (result) =>
@mmResponseHandler(params, result)
该规范将在其当前版本中运行