Added unit test for jumping to a function in exports.

Modified _waitForJump to wait until the jump promise is done, rather than checking that the cursor had changed.
Updated 1 other test which was looking at everything that was exported from the test module.
This commit is contained in:
Erik Tierney committed 2013-06-17 14:50:16 -04:00
1 parent 269c3b77c9
commit 0f73f04bcc
3 files changed
+33 -8

No files matched your search

@@ -7,4 +7,10 @@ define(function (require, exports, module) {
return "a string";
};
exports.j = "hi";
function c() {
}
exports.c = c;
});
@@ -155,6 +155,11 @@ function testNonAscii() {
}
require(["MyModule"], function (myModule) {
'use strict';
var x = myModule.c;
});
/* Add large comment to make this test over 250 lines which will trigger
* partial updates to be used.
*
@@ -291,13 +291,18 @@ define(function (require, exports, module) {
* @param {{line:number, ch:number}} oldLocation - the original line/col
* @param {Function} callback - the callback to apply once the editor has changed position
*/
function _waitForJump(oldLocation, callback) {
var cursor = null;
function _waitForJump(jumpPromise, callback) {
var cursor = null,
complete = false;
jumpPromise.done(function () {
complete = true;
});
waitsFor(function () {
var activeEditor = EditorManager.getActiveEditor();
cursor = activeEditor.getCursorPos();
return (cursor.line !== oldLocation.line) ||
(cursor.ch !== oldLocation.ch);
return complete;
}, "Expected jump did not occur", 3000);
runs(function () { callback(cursor); });
@@ -314,10 +319,10 @@ define(function (require, exports, module) {
function editorJumped(expectedLocation) {
var oldLocation = testEditor.getCursorPos();
JSCodeHints.handleJumpToDefinition();
var jumpPromise = JSCodeHints.handleJumpToDefinition();
_waitForJump(oldLocation, function (newCursor) {
_waitForJump(jumpPromise, function (newCursor) {
expect(newCursor.line).toBe(expectedLocation.line);
expect(newCursor.ch).toBe(expectedLocation.ch);
if (expectedLocation.file) {
@@ -739,7 +744,7 @@ define(function (require, exports, module) {
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentExact(hintObj, ["a", "b", "j"]);
hintsPresentExact(hintObj, ["a", "b", "c", "j"]);
});
});
@@ -998,7 +1003,7 @@ define(function (require, exports, module) {
editorJumped({line: 4, ch: 13, file: "MyModule.js"}); //jump to another file
});
});
it("should jump to the method definition in .prototype", function () {
var start = { line: 59, ch: 8 };
@@ -1035,6 +1040,15 @@ define(function (require, exports, module) {
});
});
it("should jump to the actual function definition, and not the exports line", function () {
var start = { line: 159, ch: 22 };
testEditor.setCursorPos(start);
runs(function () {
editorJumped({line: 11, ch: 14, file: "MyModule.js"}); //jump to another file
});
});
it("should not hint function, variable, or param decls", function () {
var func = { line: 7, ch: 12 },
param = { line: 7, ch: 18 },