Merge branch 'bonkevin-spec-suite-properties-accessors'
* Merges #2072 from @bonkevin * Adds Env#getSpecProperty
This commit is contained in:
@@ -78,6 +78,17 @@ describe('Spec', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getSpecProperty', function() {
|
||||
it('get the property value', function() {
|
||||
const spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: () => {} }
|
||||
});
|
||||
|
||||
spec.setSpecProperty('a', 4);
|
||||
expect(spec.getSpecProperty('a')).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setSpecProperty', function() {
|
||||
it('adds the property to the result', function() {
|
||||
const spec = new jasmineUnderTest.Spec({
|
||||
@@ -88,6 +99,21 @@ describe('Spec', function() {
|
||||
|
||||
expect(spec.result.properties).toEqual({ a: 4 });
|
||||
});
|
||||
|
||||
it('replace the property result when it was previously set', function() {
|
||||
const spec = new jasmineUnderTest.Spec({
|
||||
queueableFn: { fn: () => {} }
|
||||
});
|
||||
|
||||
spec.setSpecProperty('a', 'original-value');
|
||||
spec.setSpecProperty('b', 'original-value');
|
||||
spec.setSpecProperty('a', 'new-value');
|
||||
|
||||
expect(spec.result.properties).toEqual({
|
||||
a: 'new-value',
|
||||
b: 'original-value'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('#status returns passing by default', function() {
|
||||
|
||||
@@ -2262,17 +2262,54 @@ describe('Env integration', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('throws an exception if you try to getSpecProperty outside of a spec', async function() {
|
||||
const env = new jasmineUnderTest.Env();
|
||||
let exception;
|
||||
|
||||
env.describe('a suite', function() {
|
||||
env.it('a spec');
|
||||
try {
|
||||
env.getSpecProperty('a prop');
|
||||
} catch (e) {
|
||||
exception = e;
|
||||
}
|
||||
env.it('has a test', function() {});
|
||||
});
|
||||
|
||||
await env.execute();
|
||||
|
||||
expect(exception.message).toBe(
|
||||
"'getSpecProperty' was used when there was no current spec"
|
||||
);
|
||||
});
|
||||
|
||||
it('reports test properties on specs', async function() {
|
||||
const env = new jasmineUnderTest.Env(),
|
||||
reporter = jasmine.createSpyObj('reporter', ['suiteDone', 'specDone']);
|
||||
|
||||
reporter.specDone.and.callFake(function(e) {
|
||||
expect(e.properties).toEqual({ a: 'Bee' });
|
||||
expect(e.properties).toEqual({
|
||||
fromBeforeEach: 'Pie',
|
||||
fromSpecInnerCallback: 'Bee',
|
||||
willChangeInAfterEach: 2,
|
||||
fromAfterEach: 'Cheese'
|
||||
});
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
env.beforeEach(function() {
|
||||
env.setSpecProperty('fromBeforeEach', 'Pie');
|
||||
});
|
||||
env.afterEach(function() {
|
||||
env.setSpecProperty(
|
||||
'willChangeInAfterEach',
|
||||
env.getSpecProperty('willChangeInAfterEach') + 1
|
||||
);
|
||||
env.setSpecProperty('fromAfterEach', 'Cheese');
|
||||
});
|
||||
env.it('calls setSpecProperty', function() {
|
||||
env.setSpecProperty('a', 'Bee');
|
||||
env.setSpecProperty('fromSpecInnerCallback', 'Bee');
|
||||
env.setSpecProperty('willChangeInAfterEach', 1);
|
||||
});
|
||||
await env.execute();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user