diff --git a/src/extensions/default/JavaScriptCodeHints/unittests.js b/src/extensions/default/JavaScriptCodeHints/unittests.js index 9c0599cde..8bf4e5096 100644 --- a/src/extensions/default/JavaScriptCodeHints/unittests.js +++ b/src/extensions/default/JavaScriptCodeHints/unittests.js @@ -49,26 +49,15 @@ define(function (require, exports, module) { DocumentManager.setCurrentDocument(doc); }); }); + /** - * Returns an Editor suitable for use in isolation, given a Document. (Unlike - * SpecRunnerUtils.createMockEditor(), which is given text and creates the Document - * for you). + * Returns an Editor suitable for use in isolation, given a Document. * * @param {Document} doc - the document to be contained by the new Editor * @return {Editor} - the mock editor object */ function createMockEditor(doc) { - // Initialize EditorManager - var $editorHolder = $("
"); - EditorManager.setEditorHolder($editorHolder); - $("body").append($editorHolder); - - // create Editor instance - var editor = new Editor(doc, true, $editorHolder.get(0)); - - EditorManager._notifyActiveEditorChanged(editor); - - return editor; + return SpecRunnerUtils.createMockEditorForDocument(doc); } describe("JavaScript Code Hinting", function () { diff --git a/test/spec/SpecRunnerUtils.js b/test/spec/SpecRunnerUtils.js index 7a7fb4be0..29b26a716 100644 --- a/test/spec/SpecRunnerUtils.js +++ b/test/spec/SpecRunnerUtils.js @@ -205,26 +205,34 @@ define(function (require, exports, module) { } /** - * Returns a Document and Editor suitable for use with an Editor in - * isolation: i.e., a Document that will never be set as the - * currentDocument or added to the working set. - * @return {!{doc:{Document}, editor:{Editor}}} + * Returns an Editor tied to the given Document, but suitable for use in isolation + * (without being placed inside the surrounding Brackets UI). + * @return {!Editor} */ - function createMockEditor(initialContent, languageId, visibleRange) { + function createMockEditorForDocument(doc, visibleRange) { // Initialize EditorManager/PanelManager and position the editor-holder offscreen // (".content" may not exist, but that's ok for headless tests where editor height doesn't matter) var $editorHolder = createMockElement().attr("id", "mock-editor-holder"); PanelManager._setMockDOM($(".content"), $editorHolder); EditorManager.setEditorHolder($editorHolder); - // create dummy Document for the Editor - var doc = createMockDocument(initialContent, languageId); - // create Editor instance var editor = new Editor(doc, true, $editorHolder.get(0), visibleRange); EditorManager._notifyActiveEditorChanged(editor); - return { doc: doc, editor: editor }; + return editor; + } + + /** + * Returns a Document and Editor suitable for use in isolation: i.e., the Document + * will never be set as the currentDocument or added to the working set and the + * Editor does not live inside a full-blown Brackets UI layout. + * @return {!{doc:!Document, editor:!Editor}} + */ + function createMockEditor(initialContent, languageId, visibleRange) { + // create dummy Document, then Editor tied to it + var doc = createMockDocument(initialContent, languageId); + return { doc: doc, editor: createMockEditorForDocument(doc, visibleRange) }; } /** @@ -944,6 +952,7 @@ define(function (require, exports, module) { exports.createMockDocument = createMockDocument; exports.createMockActiveDocument = createMockActiveDocument; exports.createMockElement = createMockElement; + exports.createMockEditorForDocument = createMockEditorForDocument; exports.createMockEditor = createMockEditor; exports.createTestWindowAndRun = createTestWindowAndRun; exports.closeTestWindow = closeTestWindow;