Skip to content

Commit

Permalink
Write spec for binding items
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprey committed Aug 9, 2019
1 parent f29e6b1 commit 89c7147
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/svelte3/integration/bind/bind.declared.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ShopingCart bind:totalCost={totalCost} />

<script>
import ShopingCart from './ShopingCart.svelte';
let totalCost;
</script>
5 changes: 5 additions & 0 deletions test/svelte3/integration/bind/bind.named.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ShopingCart bind:totalCost={cost} />

<script>
import ShopingCart from './ShopingCart.svelte';
</script>
5 changes: 5 additions & 0 deletions test/svelte3/integration/bind/bind.simple.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ShopingCart bind:totalCost />

<script>
import ShopingCart from './ShopingCart.svelte';
</script>
85 changes: 85 additions & 0 deletions test/svelte3/integration/bind/bind.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const path = require('path');
const chai = require('chai');
const expect = chai.expect;

const parser = require('../../../../index');

describe('SvelteDoc v3 - Bind', () => {
it('Bind simple definition should be parsed', (done) => {
parser.parse({
version: 3,
filename: path.resolve(__dirname, 'bind.simple.svelte'),
features: ['data'],
ignoredVisibilities: []
}).then((doc) => {
expect(doc, 'Document should be provided').to.exist;
expect(doc.data, 'Document data should be parsed').to.exist;

expect(doc.data.length).to.equal(1);
const item = doc.data[0];

expect(item, 'Bind item should be a valid entity').to.exist;
expect(item.name).to.equal('totalCost');
expect(item.visibility).to.equal('private');
expect(item.bind, 'Bind information should be presented').to.exist;
expect(item.bind.source).to.equal('ShopingCart');
expect(item.bind.property).to.equal('totalCost');

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

it('Bind named definition should be parsed', (done) => {
parser.parse({
version: 3,
filename: path.resolve(__dirname, 'bind.named.svelte'),
features: ['data'],
ignoredVisibilities: []
}).then((doc) => {
expect(doc, 'Document should be provided').to.exist;
expect(doc.data, 'Document data should be parsed').to.exist;

expect(doc.data.length).to.equal(1);
const item = doc.data[0];

expect(item, 'Bind item should be a valid entity').to.exist;
expect(item.name).to.equal('cost');
expect(item.visibility).to.equal('private');
expect(item.bind, 'Bind information should be presented').to.exist;
expect(item.bind.source).to.equal('ShopingCart');
expect(item.bind.property).to.equal('totalCost');

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

it('Bind declared definition should be parsed', (done) => {
parser.parse({
version: 3,
filename: path.resolve(__dirname, 'bind.declared.svelte'),
features: ['data'],
ignoredVisibilities: []
}).then((doc) => {
expect(doc, 'Document should be provided').to.exist;
expect(doc.data, 'Document data should be parsed').to.exist;

expect(doc.data.length).to.equal(1);
const item = doc.data[0];

expect(item, 'Bind item should be a valid entity').to.exist;
expect(item.name).to.equal('totalCost');
expect(item.visibility).to.equal('private');
expect(item.bind, 'Bind information should be presented').to.exist;
expect(item.bind.source).to.equal('ShopingCart');
expect(item.bind.property).to.equal('totalCost');

done();
}).catch(e => {
done(e);
});
});
});
18 changes: 18 additions & 0 deletions typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ export interface ISvelteItem {
keywords?: JSDocKeyword[];
}

export interface SvelteDataBindMapping {
/**
* The parent component name or DOM element from which are was binded.
*/
source: string;

/**
* The name of the property which are was binded.
*/
property: string;
}

export interface SvelteDataItem extends ISvelteItem {
/**
* The JS type of property.
Expand All @@ -87,6 +99,12 @@ export interface SvelteDataItem extends ISvelteItem {
* @since {2.0.0}
*/
let?: 'var'|'let'|'const';
/**
* Provides information about property binding.
* @since Svelte V3
* @since {2.1.0}
*/
bind?: SvelteDataBindMapping;
/**
* Indicates that this data item of component located in static context.
* Variable should be declared in `<script scope="module" />` block.
Expand Down

0 comments on commit 89c7147

Please sign in to comment.