From 89c71471746cbcd38a051f902ee80951a24f1c66 Mon Sep 17 00:00:00 2001 From: Alexey Mulyukin Date: Fri, 9 Aug 2019 13:54:24 +0300 Subject: [PATCH] Write spec for binding items --- .../integration/bind/bind.declared.svelte | 7 ++ .../integration/bind/bind.named.svelte | 5 ++ .../integration/bind/bind.simple.svelte | 5 ++ test/svelte3/integration/bind/bind.spec.js | 85 +++++++++++++++++++ typings.d.ts | 18 ++++ 5 files changed, 120 insertions(+) create mode 100644 test/svelte3/integration/bind/bind.declared.svelte create mode 100644 test/svelte3/integration/bind/bind.named.svelte create mode 100644 test/svelte3/integration/bind/bind.simple.svelte create mode 100644 test/svelte3/integration/bind/bind.spec.js diff --git a/test/svelte3/integration/bind/bind.declared.svelte b/test/svelte3/integration/bind/bind.declared.svelte new file mode 100644 index 0000000..f603171 --- /dev/null +++ b/test/svelte3/integration/bind/bind.declared.svelte @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/test/svelte3/integration/bind/bind.named.svelte b/test/svelte3/integration/bind/bind.named.svelte new file mode 100644 index 0000000..47c3d29 --- /dev/null +++ b/test/svelte3/integration/bind/bind.named.svelte @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/test/svelte3/integration/bind/bind.simple.svelte b/test/svelte3/integration/bind/bind.simple.svelte new file mode 100644 index 0000000..c968abe --- /dev/null +++ b/test/svelte3/integration/bind/bind.simple.svelte @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/test/svelte3/integration/bind/bind.spec.js b/test/svelte3/integration/bind/bind.spec.js new file mode 100644 index 0000000..146ab0c --- /dev/null +++ b/test/svelte3/integration/bind/bind.spec.js @@ -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); + }); + }); +}); \ No newline at end of file diff --git a/typings.d.ts b/typings.d.ts index 623f792..eaadfda 100644 --- a/typings.d.ts +++ b/typings.d.ts @@ -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. @@ -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 `