File tree Expand file tree Collapse file tree 5 files changed +16
-17
lines changed
1-js/06-advanced-functions/09-call-apply-decorators/01-spy-decorator Expand file tree Collapse file tree 5 files changed +16
-17
lines changed Original file line number Diff line number Diff line change 11function spy ( func ) {
22
33 function wrapper ( ...args ) {
4- // usando ...args ao invés de arguments para guardar o "verdadeiro" array dentro de wrapper.calls
4+ // usar `...args` ao invés de `arguments`
5+ // para armazenar o vetor "real" no `wrapper.calls`
56 wrapper . calls . push ( args ) ;
67 return func . apply ( this , args ) ;
78 }
Original file line number Diff line number Diff line change 11function spy ( func ) {
2- // o seu código
2+ // o teu código
33}
44
Original file line number Diff line number Diff line change 11describe ( "spy" , function ( ) {
2- it ( "guarde as chamadas dentro da sua propriedade " , function ( ) {
2+ it ( "records calls into its property " , function ( ) {
33 function work ( ) { }
44
55 work = spy ( work ) ;
@@ -17,19 +17,18 @@ describe("spy", function() {
1717 ] ) ;
1818 } ) ;
1919
20- it ( "encapsula transparentemente as funções " , function ( ) {
21-
20+ it ( "transparently wraps functions " , function ( ) {
21+
2222 let sum = sinon . spy ( ( a , b ) => a + b ) ;
2323
2424 let wrappedSum = spy ( sum ) ;
2525
2626 assert . equal ( wrappedSum ( 1 , 2 ) , 3 ) ;
27- assert ( sum . calledWith ( 1 , 2 ) ) ;
27+ assert ( sum . calledWidth ( 1 , 2 ) ) ;
2828 } ) ;
2929
30-
31- it ( "encapsula transparentemente os métodos" , function ( ) {
32-
30+ it ( "transparently wraps methods" , function ( ) {
31+
3332 let calc = {
3433 sum : sinon . spy ( ( a , b ) => a + b )
3534 } ;
@@ -40,5 +39,4 @@ describe("spy", function() {
4039 assert ( calc . sum . calledWith ( 1 , 2 ) ) ;
4140 assert ( calc . sum . calledOn ( calc ) ) ;
4241 } ) ;
43-
44- } ) ;
42+ } ) ;
Original file line number Diff line number Diff line change 1- O encapsulador retornado por ` spy(f) ` deve guardar todos os argumentos e depois usar ` f.apply ` para encaminhar a chamada.
1+ O embrulhador retornado pela ` spy(f) ` deve armazenar todos os argumentos e então usar ` f.apply ` para encaminhar a chamada.
Original file line number Diff line number Diff line change @@ -2,17 +2,17 @@ importance: 5
22
33---
44
5- # Decorador Spy (espião)
5+ # Decorador de Espionagem
66
7- Crie um decorador ` spy(func) ` que retorne um encapsulador que guarde todas as chamadas de uma função na sua propriedade ` calls ` .
7+ Cria um decorador ` spy(func) ` que retorna um embrulhador que guarde todas as chamadas à função na sua propriedade ` calls ` .
88
9- Todas as chamadas são guardadas num array de argumentos.
9+ Toda chamada é guardada num vetor de argumentos.
1010
1111Por exemplo:
1212
1313``` js
1414function work (a , b ) {
15- alert ( a + b ); // work é uma função ou método arbitrários
15+ alert ( a + b ); // ` work` é uma função ou método arbitrário
1616}
1717
1818* ! *
@@ -27,4 +27,4 @@ for (let args of work.calls) {
2727}
2828```
2929
30- P.S. Esse decorador é algumas vezes útil para testes unitários. Sua forma avançada é ` sinon.spy ` na biblioteca [ Sinon.JS] ( http://sinonjs.org ) .
30+ Pós-escrito: Este decorador é algumas vezes útil para testes unitários. Sua forma avançada é ` sinon.spy ` na biblioteca [ Sinon.JS] ( http://sinonjs.org ) .
You can’t perform that action at this time.
0 commit comments