add rimraf for windows users.

This commit is contained in:
ttsah
2019-02-20 09:46:18 +02:00
parent 1e3fc4f4b0
commit 28b0631a4a
3 changed files with 73 additions and 28 deletions
+3 -3
View File
@@ -42,9 +42,9 @@ export function react2angular<Props>(
render() {
if (!this.isDestroyed) {
render(
<Class {...this.props} {...this.injectedProps as any} />,
this.$element[0]
)
<Class {...this.props} {...this.injectedProps as any} />,
this.$element[0]
)
}
}
componentWillUnmount() {
+3 -3
View File
@@ -6,9 +6,9 @@
"main:esnext": "index.es2015.js",
"typings": "index.d.ts",
"scripts": {
"build": "npm run clean && tsc -d -t es2015 && mv ./index.js ./index.es2015.js && tsc -t es5",
"build": "npm run clean && npm run lint && tsc -d -t es2015 && mv ./index.js ./index.es2015.js && tsc -t es5",
"clean": "rimraf ./*.d.ts && rimraf ./*.map",
"lint": "tslint -p ./tsconfig.json index.tsx test.tsx",
"lint": "tslint --fix -p ./tsconfig.json index.tsx test.tsx",
"pretest": "npm run build",
"prepublishOnly": "npm test",
"test": "karma start --single-run",
@@ -52,7 +52,7 @@
"@types/prop-types": "^15.5.8",
"@types/react": "^16.8.1",
"@types/react-dom": "^16.0.11",
"angular-mocks": "^1.7.6",
"angular-mocks": "1.6.9",
"angular-resource": "^1.7.6",
"browserify": "^16.2.3",
"jasmine": "^3.3.1",
+67 -22
View File
@@ -1,4 +1,13 @@
import { bootstrap, element as $, IAugmentedJQuery, ICompileService, IHttpService, IQService, module } from 'angular'
import {
bootstrap,
element as $,
IAugmentedJQuery,
ICompileService,
IComponentOptions, IController,
IHttpService,
IQService, IScope,
module
} from 'angular'
import * as angular from 'angular'
import 'angular-mocks'
import { $http, $q, $rootScope } from 'ngimport'
@@ -103,19 +112,49 @@ function TestSeven(props: Props) {
}
interface TestEightProps {
onComponentWillUnmount: any,
onRender: any,
onChange: jasmine.Spy,
onComponentWillUnmount: jasmine.Spy,
onRender: jasmine.Spy,
values: string[],
}
class TestEight extends React.Component<TestEightProps> {
render() {
this.props.onRender()
return this.props.values.map((value, index) => <div key={index}>{value}</div>)
return this.props.values
.map((value, index) => <div key={index}>{value}</div>)
}
componentWillUnmount() {
this.props.onComponentWillUnmount()
this.props.onChange(this.props.values
.map(val => `${val}ss`))
}
}
class TestEightWrapper implements IComponentOptions {
bindings = {
onComponentWillUnmount: '<',
onRender: '<',
values: '<'
}
template = `<test-angular-eight
on-change="$ctrl.onChange"
on-component-will-unmount="$ctrl.onComponentWillUnmount"
on-render="$ctrl.onRender"
values="$ctrl.values">
</test-angular-eight>`
controller = class implements IController {
values!: string[]
constructor(
private $scope: IScope
){}
onChange = (values: string[]) => {
this.values = values
this.$scope.$apply()
}
}
}
@@ -125,7 +164,7 @@ const TestAngularThree = react2angular(TestThree)
const TestAngularFour = react2angular(TestFour)
const TestAngularSix = react2angular(TestSix, ['foo'], ['$http', '$element', 'testSixService', 'foo'])
const TestAngularSeven = react2angular(TestSeven, null, ['foo'])
const TestAngularEight = react2angular(TestEight, ['values', 'onComponentWillUnmount', 'onRender'])
const TestAngularEight = react2angular(TestEight, ['values', 'onComponentWillUnmount', 'onRender', 'onChange'])
module('test', ['bcherny/ngimport'])
.component('testAngularOne', TestAngularOne)
@@ -137,6 +176,7 @@ module('test', ['bcherny/ngimport'])
.component('testAngularSix', TestAngularSix)
.component('testAngularSeven', TestAngularSeven)
.component('testAngularEight', TestAngularEight)
.component('testAngularEightWrapper', new TestEightWrapper())
bootstrap($(), ['test'], { strictDi: true })
@@ -374,25 +414,30 @@ describe('react2angular', () => {
expect(element.find('span').length).toBe(0)
})
// it('should not call render after component unmount', () => {
// const componentWillUnmountSpy = jasmine.createSpy('componentWillUnmount')
// const renderSpy = jasmine.createSpy('render')
it('should not call render after component unmount', () => {
const componentWillUnmountSpy = jasmine.createSpy('componentWillUnmount')
const renderSpy = jasmine.createSpy('render')
// const scope = Object.assign($rootScope.$new(true), {
// onComponentWillUnmount: componentWillUnmountSpy,
// onRender: renderSpy,
// values: ['val1']
// })
// const element = $(`<test-angular-eight values="values"></test-angular-eight>`)
const scope = Object.assign($rootScope.$new(true), {
onComponentWillUnmount: componentWillUnmountSpy,
onRender: renderSpy,
values: ['val1']
})
const element = $(`<test-angular-eight-wrapper
on-render="onRender"
on-component-will-unmount="onComponentWillUnmount"
values="values">
</test-angular-eight-wrapper>`)
// $compile(element)(scope)
// $rootScope.$apply()
// scope.values = ['newVal1']
// scope.$destroy()
// expect(componentWillUnmountSpy).not.toHaveBeenCalledBefore(renderSpy)
// })
$compile(element)(scope)
const innerScope = angular
.element(element.find('test-angular-eight'))
.scope()
$rootScope.$apply()
renderSpy.calls.reset()
innerScope.$destroy()
expect(componentWillUnmountSpy).not.toHaveBeenCalledBefore(renderSpy)
})
})
})