Only call webCrypto.generateKey once in tests
This commit is contained in:
parent
8ec01ae07a
commit
49c9fb193d
|
@ -1,11 +1,34 @@
|
||||||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
|
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
|
||||||
|
|
||||||
|
const stub = require('sinon/lib/sinon/stub');
|
||||||
const chai = require('chai');
|
const chai = require('chai');
|
||||||
chai.use(require('chai-as-promised'));
|
chai.use(require('chai-as-promised'));
|
||||||
|
|
||||||
const { expect } = chai;
|
const { expect } = chai;
|
||||||
|
|
||||||
describe('Key', function() {
|
describe('Key', function() {
|
||||||
|
let webCrypto = openpgp.util.getWebCryptoAll();
|
||||||
|
|
||||||
|
if (webCrypto) {
|
||||||
|
let generateKey = webCrypto.generateKey;
|
||||||
|
let keyGenStub;
|
||||||
|
let keyGenValue;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
keyGenStub = stub(webCrypto, 'generateKey');
|
||||||
|
keyGenStub.callsFake(function() {
|
||||||
|
if (!keyGenValue) {
|
||||||
|
keyGenValue = generateKey.apply(webCrypto, arguments);
|
||||||
|
}
|
||||||
|
return keyGenValue;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
keyGenStub.restore();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
describe('V4', tests);
|
describe('V4', tests);
|
||||||
|
|
||||||
describe('V5', function() {
|
describe('V5', function() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user