import { beforeHook, afterHook, browser } from 'karma-event-driver-ext/cjs/event-driver-hooks';
import React from 'dist/React'
import {SyntheticEvent, addEvent} from 'src/event'
import {DOMElement} from 'src/browser'

describe('生命周期例子', function () {
    this.timeout(200000);
    before(async() => {
        await beforeHook();
    });
    after(async() => {
        await afterHook(false);
    })
    var body = document.body, div
    beforeEach(function () {
        div = document.createElement('div')
        body.appendChild(div)
    })
    afterEach(function () {
        body.removeChild(div)
    })
    it('如果在componentDidMount中调用setState方法\n那么setState的所有回调，\n都会延迟到componentDidUpdate中执行', async() => {
        var list = []
        class App extends React.Component {
            constructor(props) {
                super(props)
                this.state = {
                    aaa: 'aaa'
                }
            }
            componentWillMount() {
                this.setState({
                    aaa: 'bbb'
                }, function(){
                    list.push('1111')
                })
            }
            componentDidMount() {
                this.setState({
                    aaa: 'cccc'
                }, function(){
                    list.push('2222')
                })
                this.setState({
                    aaa: 'dddd'
                }, function(){
                    list.push('3333')
                })
                list.push('did mount')
            }
          
            componentWillUpdate() {
                list.push('will update')
            }
            componentDidUpdate() {
                list.push('did update')
            }
            render() {
                list.push(this.state.aaa)
                return <div>{this.state.aaa}</div>

            }
        }
   
        var s = ReactDOM.render(
            <App/>, div);
        await browser
            .pause(300)
            .$apply()
        expect(list.join('')).toBe('bbb-did mount-will update-dddd-1111-2222-3333')
       
       
    })

})