No Description

assert.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React, {Component} from 'react';
  2. import {
  3. AppRegistry,
  4. StyleSheet,
  5. Text,
  6. View,
  7. Platform,
  8. ScrollView,
  9. Image,
  10. } from 'react-native';
  11. export default class Assert extends Component {
  12. props : {
  13. expect : any,
  14. actual : any,
  15. desc : any,
  16. compaer : () => bool
  17. };
  18. constructor(props) {
  19. super(props)
  20. }
  21. render() {
  22. return (
  23. <View style={{
  24. padding : 16,
  25. borderLeftWidth : 5,
  26. marginTop : 4,
  27. backgroundColor : 'white',
  28. borderColor : this.getAssertion() ? '#00a825' : '#ff0d0d'
  29. }}>
  30. <Text style={{
  31. color : this.getAssertion() ? '#00a825' : '#ff0d0d',
  32. margin : 8,
  33. marginTop : 0,
  34. marginLeft : 0
  35. }}>{ this.getAssertion() ? '✅' : '×' } {this.props.desc}</Text>
  36. <Text style={{flex : 1, flexDirection : 'row'}}>
  37. <Text style={{ color : '#AAA'}}>expect </Text>
  38. <Text style={{flex : 1}}>{String(this.props.expect)}</Text>
  39. </Text>
  40. <Text style={{flex : 1, flexDirection : 'row'}}>
  41. <Text style={{color : '#AAA'}}>actual </Text>
  42. <Text style={{flex : 1}}>{String(this.props.actual)}</Text>
  43. </Text>
  44. {this.props.comparer ? <Text style={{flex : 1, flexDirection : 'row'}}>
  45. <Text style={{color : '#AAA'}}>comparer = </Text>
  46. <Text style={{flex : 1}}>
  47. { String(this.props.comparer) }
  48. </Text>
  49. </Text> : null}
  50. </View>
  51. )
  52. }
  53. getAssertion() {
  54. if(this.props.comparer)
  55. return this.props.comparer(this.props.expect, this.props.actual)
  56. else
  57. return this.props.expect === this.props.actual
  58. }
  59. }