@@ -2205,7 +2205,7 @@ describe("Sandbox", function () {
22052205 assert . equals ( object . prop , "blabla" ) ;
22062206 } ) ;
22072207
2208- it ( "allows restoring setters" , function ( ) {
2208+ it ( "allows putting setters on fields and subsequently restoring them " , function ( ) {
22092209 const object = {
22102210 prop : "bar" ,
22112211 } ;
@@ -2221,6 +2221,37 @@ describe("Sandbox", function () {
22212221
22222222 assert . equals ( object . prop , "bla" ) ;
22232223 } ) ;
2224+
2225+ it ( "allows replacing setters on fields and subsequently restoring them" , function ( ) {
2226+ const object = {
2227+ get prop ( ) {
2228+ return "bar" ;
2229+ } ,
2230+ } ;
2231+
2232+ const sandbox = new Sandbox ( ) ;
2233+ const getter = sandbox . spy ( ( ) => "foobar" ) ;
2234+ sandbox . stub ( object , "prop" ) . get ( getter ) ;
2235+ assert . equals ( object . prop , "foobar" ) ;
2236+ assert . equals ( getter . callCount , 1 ) ;
2237+
2238+ sandbox . restore ( ) ;
2239+ assert . equals ( object . prop , "bar" ) ;
2240+ } ) ;
2241+
2242+ it ( "allows spying on accessors and subsequently restoring them" , function ( ) {
2243+ const object = {
2244+ get prop ( ) {
2245+ return "bar" ;
2246+ } ,
2247+ } ;
2248+ const sandbox = new Sandbox ( ) ;
2249+ const spy = sandbox . spy ( object , "prop" , [ "get" ] ) ;
2250+ sandbox . restore ( ) ;
2251+ const descriptor = Object . getOwnPropertyDescriptor ( object , "prop" ) ;
2252+ const getter = descriptor . get ;
2253+ refute . equals ( getter , spy . get ) ;
2254+ } ) ;
22242255 } ) ;
22252256
22262257 describe ( ".assert" , function ( ) {
0 commit comments