Add toBeInstanceOf and toHaveLength jasmine matchers

This commit is contained in:
Corey Johnson & Nathan Sobo
2013-03-07 11:04:17 -08:00
parent 98c9012bdb
commit ff50bc2e6f
2 changed files with 76 additions and 4 deletions

View File

@@ -68,6 +68,8 @@ beforeEach ->
spyOn($native, 'writeToPasteboard').andCallFake (text) -> pasteboardContent = text
spyOn($native, 'readFromPasteboard').andCallFake -> pasteboardContent
addCustomMatchers(this)
afterEach ->
keymap.bindingSets = bindingSetsToRestore
keymap.bindingSetsByFirstKeystrokeToRestore = bindingSetsByFirstKeystrokeToRestore
@@ -121,6 +123,18 @@ jasmine.unspy = (object, methodName) ->
throw new Error("Not a spy") unless object[methodName].originalValue?
object[methodName] = object[methodName].originalValue
addCustomMatchers = (spec) ->
spec.addMatchers
toBeInstanceOf: (expected) ->
notText = if @isNot then " not" else ""
this.message = => "Expected #{jasmine.pp(@actual)} to#{notText} be instance of #{expected.name} class"
@actual instanceof expected
toHaveLength: (expected) ->
notText = if @isNot then " not" else ""
this.message = => "Expected object with length #{@actual.length} to#{notText} have length #{expected}"
@actual.length == expected
window.keyIdentifierForKey = (key) ->
if key.length > 1 # named key
key

View File

@@ -1,14 +1,72 @@
$ = require 'jquery'
RootView = require 'root-view'
MarkdownPreview = require 'markdown-preview/lib/markdown-preview-view'
MarkdownPreviewView = require 'markdown-preview/lib/markdown-preview-view'
_ = require 'underscore'
describe "MarkdownPreview", ->
describe "MarkdownPreviewView", ->
beforeEach ->
project.setPath(project.resolve('markdown'))
window.rootView = new RootView
window.loadPackage("markdown-preview")
spyOn(MarkdownPreview.prototype, 'loadHtml')
spyOn(MarkdownPreviewView.prototype, 'loadHtml')
fdescribe "markdown-preview:show", ->
beforeEach ->
rootView.open("file.markdown")
describe "when the active item is an edit session", ->
beforeEach ->
rootView.attachToDom()
describe "when a preview item has not been created for the edit session's uri", ->
describe "when there is more than one pane", ->
it "shows a markdown preview for the current buffer on the next pane", ->
rootView.getActivePane().splitRight()
[pane1, pane2] = rootView.getPanes()
pane1.focus()
rootView.getActiveView().trigger 'markdown-preview:show'
preview = pane2.activeItem
expect(preview).toBeInstanceOf(MarkdownPreviewView)
expect(preview.buffer).toBe rootView.getActivePaneItem().buffer
expect(pane1).toMatchSelector(':has(:focus)')
describe "when there is only one pane", ->
it "splits the current pane to the right with a markdown preview for the current buffer", ->
expect(rootView.getPanes()).toHaveLength 1
rootView.getActiveView().trigger 'markdown-preview:show'
expect(rootView.getPanes()).toHaveLength 2
[pane1, pane2] = rootView.getPanes()
expect(pane2.items).toHaveLength 1
preview = pane2.activeItem
expect(preview).toBeInstanceOf(MarkdownPreviewView)
expect(preview.buffer).toBe rootView.getActivePaneItem().buffer
expect(pane1).toMatchSelector(':has(:focus)')
describe "when a preview item has already been created for the edit session's uri", ->
it "updates and shows the existing preview item if it isn't displayed", ->
rootView.getActiveView().trigger 'markdown-preview:show'
[pane1, pane2] = rootView.getPanes()
pane2.focus()
expect(rootView.getActivePane()).toBe pane2
preview = pane2.activeItem
expect(preview).toBeInstanceOf(MarkdownPreviewView)
rootView.open()
expect(pane2.activeItem).not.toBe preview
pane1.focus()
rootView.getActiveView().trigger 'markdown-preview:show'
expect(rootView.getPanes()).toHaveLength 2
expect(pane2.getItems()).toHaveLength 2
expect(pane2.activeItem).toBe preview
expect(pane1).toMatchSelector(':has(:focus)')
describe "when the active item is not an edit session ", ->
it "logs a warning to the console saying that it isn't possible to preview the item", ->
describe "markdown-preview:toggle event", ->
it "toggles on/off a preview for a .md file", ->
@@ -50,7 +108,7 @@ describe "MarkdownPreview", ->
expect(rootView.find('.markdown-preview')).not.toExist()
editor.trigger('markdown-preview:toggle')
expect(rootView.find('.markdown-preview')).not.toExist()
expect(MarkdownPreview.prototype.loadHtml).not.toHaveBeenCalled()
expect(MarkdownPreviewView.prototype.loadHtml).not.toHaveBeenCalled()
describe "core:cancel event", ->
it "removes markdown preview", ->