Skip to content

Commit

Permalink
Eliminate all console errors during test run
Browse files Browse the repository at this point in the history
FREEBIE
  • Loading branch information
scottnonnenberg committed May 23, 2017
1 parent f6c62e4 commit 3cfac58
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
19 changes: 10 additions & 9 deletions js/signal_protocol_store.js
Expand Up @@ -136,15 +136,16 @@
removePreKey: function(keyId) {
var prekey = new PreKey({id: keyId});

new Promise(function(resolve) {
getAccountManager().refreshPreKeys().then(resolve);
});

return new Promise(function(resolve) {
prekey.destroy().then(function() {
resolve();
});
});
return Promise.all([
new Promise(function(resolve) {
getAccountManager().refreshPreKeys().then(resolve);
}),
new Promise(function(resolve) {
prekey.destroy().then(function() {
resolve();
});
})
]);
},

/* Returns a signed keypair object or undefined */
Expand Down
6 changes: 4 additions & 2 deletions js/views/network_status_view.js
Expand Up @@ -9,8 +9,10 @@
initialize: function() {
this.$el.hide();

var renderIntervalHandle = setInterval(this.update.bind(this), 5000);
extension.windows.onClosed(function () { clearInterval(renderIntervalHandle); });
this.renderIntervalHandle = setInterval(this.update.bind(this), 5000);
extension.windows.onClosed(function () {
clearInterval(this.renderIntervalHandle);
}.bind(this));

setTimeout(this.finishConnectingGracePeriod.bind(this), 5000);

Expand Down
6 changes: 5 additions & 1 deletion test/fixtures_test.js
Expand Up @@ -2,10 +2,14 @@

describe("Fixtures", function() {
before(function(done) {
// NetworkStatusView checks this method every five seconds while showing
window.getSocketStatus = function() { return WebSocket.OPEN; };

Whisper.Fixtures.saveAll().then(function() {
done();
});
});

it('renders', function(done) {
ConversationController.updateInbox().then(function() {
var view = new Whisper.InboxView({appWindow: {contentWindow: window}});
Expand All @@ -18,6 +22,6 @@ describe("Fixtures", function() {
var view = new Whisper.InboxView({appWindow: {contentWindow: window}});
view.$el.removeClass('android').addClass('android-dark');
view.$el.prependTo($('#render-android-dark'));
}).then(done,done);
}).then(done, done);
});
});
12 changes: 12 additions & 0 deletions test/storage_test.js
Expand Up @@ -91,9 +91,21 @@ describe("SignalProtocolStore", function() {
});
});
describe('removePreKey', function() {
var oldGetAccountManager;
before(function(done) {
oldGetAccountManager = window.getAccountManager;
window.getAccountManager = function() {
return {
refreshPreKeys: function() {
return Promise.resolve();
}
};
};
store.storePreKey(2, testKey).then(done);
});
after(function() {
window.getAccountManager = oldGetAccountManager;
});
it('deletes prekeys', function(done) {
store.removePreKey(2, testKey).then(function() {
return store.loadPreKey(2).then(function(key) {
Expand Down
11 changes: 7 additions & 4 deletions test/views/network_status_view_test.js
Expand Up @@ -25,13 +25,16 @@ describe('NetworkStatusView', function() {
});
/* END stubbing globals */

beforeEach(function(done) {

beforeEach(function() {
networkStatusView = new Whisper.NetworkStatusView();
$('.network-status-container').append(networkStatusView.el);
// stubbing global
done();
});
afterEach(function() {
// prevents huge number of errors on console after running tests
clearInterval(networkStatusView.renderIntervalHandle);
networkStatusView = null;
});

describe('initialization', function() {
it('should have an empty interval', function() {
assert.equal(networkStatusView.socketReconnectWaitDuration.asSeconds(), 0);
Expand Down

0 comments on commit 3cfac58

Please sign in to comment.