import * as DocumentRepository from "." ; import { createMockDocumentBy } from "../../__test__/Helper" ; import { testHtml } from "./index.test.data" ; describe ( "Basic test" , ( ) => { let sut ; see https beforeAll ( ( ) => { jest . mock ( "./Document" ) ; const mockDocument = require ( "./Document" ) ; mockDocument . getDocument . mockReturnValue ( createMockDocumentBy ( testHtml ) ) ; sut = require ( "." ) ; } ) ; describe ( "querySelectorAll" , ( ) => { it ( "要素がない" , ( ) => { const elements = sut . querySelectorAll ( "not found query" ) ; expect ( elements ) . toStrictEqual ( [ ] ) ; } ) ; it ( "要素が1つある" , ( ) => { const elements = sut . querySelectorAll ( "#test-id-unique" ) ; expect ( elements . length ) . toStrictEqual ( 1 ) ; } ) ; it ( "要素が2つ以上ある" , ( ) => { const elements = sut . querySelectorAll ( ".test-class-name-used-a-lot" ) ; expect ( elements . length ) . toStrictEqual ( 3 ) ; } ) ; } ) ; describe ( "querySelector" , ( ) => { it ( "要素がない" , ( ) => { const element = sut . querySelector ( "not found query" ) ; expect ( element ) . toStrictEqual ( undefined ) ; } ) ; it ( "要素が1つある" , ( ) => { const element = sut . querySelector ( "#test-id-unique" ) ; expect ( element ) . toMatchInlineSnapshot ( `
        <p
          id="test-id-unique"
        >
          
              This domain is established to be used for illustrative examples in documents.
              You may use this domain in examples without prior coordination or asking for permission.
            
        </p>
      ` ) ; } ) ; it ( "要素が2つ以上ある" , ( ) => { expect ( ( ) => { sut . querySelector ( ".test-class-name-used-a-lot" ) ; } ) . toThrow ( ) ; } ) ; } ) ; describe ( "querySelectorStrict" , ( ) => { it ( "要素がない" , ( ) => { expect ( ( ) => { sut . querySelectorStrict ( "not found query" ) ; } ) . toThrow ( ) ; } ) ; it ( "要素が1つある" , ( ) => { const element = sut . querySelectorStrict ( "#test-id-unique" ) ; expect ( element ) . toBeDefined ( ) ; } ) ; it ( "要素が2つ以上ある" , ( ) => { expect ( ( ) => { sut . querySelectorStrict ( ".test-class-name-used-a-lot" ) ; } ) . toThrow ( ) ; } ) ; } ) ; } ) ;