From 1e7392258df8b853bf6850da94b50233c305901f Mon Sep 17 00:00:00 2001 From: steelbrain Date: Thu, 11 Feb 2016 00:25:26 +0000 Subject: [PATCH] :new: Add specs for validateEditor --- spec/helper-spec.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/spec/helper-spec.js b/spec/helper-spec.js index 3cd6e2b..7b2695b 100644 --- a/spec/helper-spec.js +++ b/spec/helper-spec.js @@ -3,6 +3,7 @@ import * as fs from 'fs' import * as path from 'path' import { waitsForAsync, waitsForAsyncRejection } from './spec-helpers' +const helpersOfHelpers = require('../src/helpers') const helpers = require('../src/index') const bothFile = path.join(__dirname, 'fixtures', 'both.js') @@ -362,4 +363,41 @@ describe('linter helpers', function () { ) ) }) + describe('validateEditor', function () { + it('works if there\'s atom.workspace.isTextEditor', function () { + waitsForAsync(async function () { + await atom.workspace.open(somethingFile) + const textEditor = atom.workspace.getActiveTextEditor() + expect(function () { + helpersOfHelpers.validateEditor(textEditor) + }).not.toThrow() + expect(function () { + helpersOfHelpers.validateEditor(null) + }).toThrow() + expect(function () { + helpersOfHelpers.validateEditor(false) + }).toThrow() + }) + }) + it('works if there isnt atom.workspace.isTextEditor', function () { + waitsForAsync(async function () { + const _ = atom.workspace.isTextEditor + atom.workspace.isTextEditor = null + + await atom.workspace.open(somethingFile) + const textEditor = atom.workspace.getActiveTextEditor() + expect(function () { + helpersOfHelpers.validateEditor(textEditor) + }).not.toThrow() + expect(function () { + helpersOfHelpers.validateEditor(null) + }).toThrow() + expect(function () { + helpersOfHelpers.validateEditor(false) + }).toThrow() + + atom.workspace.isTextEditor = _ + }) + }) + }) })