Skip to content

Commit

Permalink
Add additional unit test around events in Svelte V3
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprey committed Jan 25, 2021
1 parent 70a308c commit e25c0a0
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
const EVENT = {
SIGNAL: {
NOTIFY: 'notify'
}
};
dispatch(EVENT['SIGNAL']['NOTIFY']);
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
NOTIFY: 'notify'
}
};
const SIMPLE_EVENT = 'plain-notify';
dispatch(EVENT.SIGNAL.NOTIFY);
dispatch(SIMPLE_EVENT);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
import { EVENT, SIMPLE_EVENT } from './sharedEvents.js';
dispatch(EVENT.SIGNAL.NOTIFY);
dispatch(SIMPLE_EVENT);
</script>
62 changes: 60 additions & 2 deletions test/svelte3/integration/events/events.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ describe('SvelteDoc v3 - Events', () => {
});
});

it('Dispatch event from code should be found when using an identifier', (done) => {
it('Dispatch event from code should be found when using an identifier from object', (done) => {
parser.parse({
version: 3,
filename: path.resolve(__dirname, 'event.dispatcher.identifier.svelte'),
Expand All @@ -333,7 +333,36 @@ describe('SvelteDoc v3 - Events', () => {
}).then((doc) => {
expect(doc, 'Document should be provided').to.exist;
expect(doc.events, 'Document events should be parsed').to.exist;
expect(doc.events.length).to.equal(1);
expect(doc.events.length).to.equal(2);

let event = doc.events[0];

expect(event, 'Event should be a valid entity').to.exist;
expect(event.name).to.equal('notify');
expect(event.visibility).to.equal('public');

event = doc.events[1];

expect(event, 'Event should be a valid entity').to.exist;
expect(event.name).to.equal('plain-notify');
expect(event.visibility).to.equal('public');

done();
}).catch(e => {
done(e);
});
});

xit('Dispatch event from code should be found when using an identifier from array', (done) => {
parser.parse({
version: 3,
filename: path.resolve(__dirname, 'event.dispatcher.arrayIdentifier.svelte'),
features: ['events'],
ignoredVisibilities: []
}).then((doc) => {
expect(doc, 'Document should be provided').to.exist;
expect(doc.events, 'Document events should be parsed').to.exist;
expect(doc.events.length).to.equal(2);

const event = doc.events[0];

Expand All @@ -346,4 +375,33 @@ describe('SvelteDoc v3 - Events', () => {
done(e);
});
});

xit('Dispatch event from code should be found when using an identifier from imported object', (done) => {
parser.parse({
version: 3,
filename: path.resolve(__dirname, 'event.dispatcher.importedIdentifier.svelte'),
features: ['events'],
ignoredVisibilities: []
}).then((doc) => {
expect(doc, 'Document should be provided').to.exist;
expect(doc.events, 'Document events should be parsed').to.exist;
expect(doc.events.length).to.equal(2);

let event = doc.events[0];

expect(event, 'Event should be a valid entity').to.exist;
expect(event.name).to.equal('notify');
expect(event.visibility).to.equal('public');

event = doc.events[1];

expect(event, 'Event should be a valid entity').to.exist;
expect(event.name).to.equal('plain-notify');
expect(event.visibility).to.equal('public');

done();
}).catch(e => {
done(e);
});
});
});
7 changes: 7 additions & 0 deletions test/svelte3/integration/events/sharedEvents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const EVENT = {
SIGNAL: {
NOTIFY: 'notify',
},
};

export const SIMPLE_EVENT = 'plain-notify';

0 comments on commit e25c0a0

Please sign in to comment.