Last active
November 18, 2021 05:09
-
-
Save gparlakov/f299011829e229c9d37cf0cb38506d97 to your computer and use it in GitHub Desktop.
Custom templates for [SCuri](https://www.npmjs.com/package/scuri)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This example shows how to apply functions to file names. | |
Functions from https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/core/src/utils/strings.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% params.forEach(p => { if(p.importPath) {%>import { <%= p.type %> } from '<%= p.importPath %>'; | |
<% }}) %>import { <%= className %> } from './<%= normalizedName %>'; | |
import { autoSpy, spyInject } from 'jasmine-auto-spies'; | |
describe('<%= className %>', () => { | |
<%params.forEach(p => {%> let <%= p.type %>Spy: <%= p.type %>; | |
<% }) %> | |
// scuri:lets | |
beforeEach( | |
waitForAsync(() => { | |
TestBed.configureTestingModule({ | |
providers: [ | |
MyDirective, | |
<%params.forEach(p => {%> { provide: <%= p.type %>, useClass: autoSpy(<%= p.type %>, '<%= p.type %>') }, | |
<% }) %> | |
// scuri:injectables | |
] | |
}); | |
directive = TestBed.inject(MyDirective); | |
<%params.forEach(p => {%> <%= p.type %>Spy = spyInject<<%= p.type %>>(TestBed.inject(<%= p.type %>)); | |
<% }) %> | |
// scuri:get-instances | |
}) | |
); | |
<% publicMethods.forEach(meth=> {if(meth != '') { %>it('when <%= meth %> is called it should', () => { | |
// arrange | |
// act | |
<%= shorthand %>.<%= meth %>(); | |
// assert | |
// expect(<%= shorthand %>).toEqual | |
}); | |
<% }}) %> | |
// scuri:methods | |
}); | |
/** scuri:template:lets:<%params.forEach(p => {%>let <%= camelize(p.type) %>Spy: <%= p.type %>; | |
<% }) %>*/ | |
/** scuri:template:injectables:<%params.forEach(p => {%>{ provide: <%= p.type %>, useClass: autoSpy(<%= p.type %>, '<%= p.type %>') }, | |
<% }) %>*/ | |
/** scuri:template:get-instances:<%params.forEach(p => {%><%= camelize(p.type) %>Spy = spyInject<<%= p.type %>>(TestBed.inject(<%= p.type %>)); | |
<% }) %>*/ | |
/** scuri:template:methods-skipDeDupe:<% publicMethods.forEach(meth=> {if(meth != '') { %>it('when <%= meth %> is called it should', () => { | |
// arrange | |
// act | |
<%= shorthand %>.<%= meth %>(); | |
// assert | |
// expect(<%= shorthand %>).toEqual | |
}); | |
<% }}) %>*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* CUSTOM TEMPLATE | |
* | |
* AVAILABLE PROPERTIES: | |
* | |
* params: {importPath: string, type: string} <% params.forEach(p => { %> | |
* name: <%= p.name %> | |
* importPath: <%= p.importPath %> | |
* type: <%= p.type %> | |
* <% }) %> | |
* specFileName: <%= specFileName %> | |
* normalizedName: <%= normalizedName %> | |
* className: <%= className %> | |
* publicMethods: <%= publicMethods %> | |
* declaration: <%= declaration %> | |
* builderExports: <%= builderExports %> | |
* constructorParams: <%= constructorParams %> | |
* shorthand: <%= shorthand %> | |
* | |
* AVAILABLE FUNCTIONS | |
* | |
* classify: <%=classify(name)%> | |
* | |
* decamelize: <%= decamelize(name) %> | |
* dasherize: <%= dasherize(name) %> | |
* camelize: <%= camelize(name) %> | |
* classify: <%= classify(name) %> | |
* underscore: <%= underscore(name) %> | |
* capitalize: <%= capitalize(name) %> | |
* levenshtein(name, specFileName): <%= levenshtein(name, specFileName) %> | |
* | |
* | |
*/ | |
<% params.forEach(p => { if(p.importPath) {%>import { <%= p.type %> } from '<%= p.importPath %>'; | |
<% }}) %>import { <%= className %> } from './<%= normalizedName %>'; | |
import { autoSpy } from 'autoSpy'; | |
describe('<%= className %>', () => { | |
<% publicMethods.forEach(meth=> {if(meth != '') { %>it('when <%= meth %> is called it should', () => { | |
// arrange | |
const { build } = setup().default(); | |
const <%= shorthand %> = build(); | |
// act | |
<%= shorthand %>.<%= meth %>(); | |
// assert | |
// expect(<%= shorthand %>).toEqual | |
}); | |
<% } else { %> | |
it('it should construct', () => { | |
// arrange | |
const { build } = setup().default(); | |
// act | |
const <%= shorthand %> = build(); | |
// assert | |
// expect(<%= shorthand %>).toEqual | |
}); | |
<% }}) %> | |
}); | |
// tslint-disable-type | |
function setup() { | |
<%= declaration %>const builder = { | |
<%= builderExports %>default() { | |
return builder; | |
}, | |
build() { | |
return new <%= className %>(<%= constructorParams %>); | |
} | |
}; | |
return builder; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment