Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
added test case for javascript partial without extension
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Oct 31, 2018
1 parent 848df35 commit d5e1dd0
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions render/js_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package render_test
package render

import (
"bytes"
Expand All @@ -8,7 +8,6 @@ import (
"strings"
"testing"

"github.com/gobuffalo/buffalo/render"
"github.com/gobuffalo/packr"
"github.com/stretchr/testify/require"
)
Expand All @@ -30,7 +29,7 @@ func Test_JavaScript(t *testing.T) {
t.Run("without a layout", func(st *testing.T) {
r := require.New(st)

j := render.New(render.Options{
j := New(Options{
TemplatesBox: packr.NewBox(tmpDir),
}).JavaScript

Expand All @@ -51,7 +50,7 @@ func Test_JavaScript(t *testing.T) {
_, err = layout.Write([]byte("<body><%= yield %></body>"))
r.NoError(err)

re := render.New(render.Options{
re := New(Options{
JavaScriptLayout: filepath.Base(layout.Name()),
TemplatesBox: packr.NewBox(tmpDir),
})
Expand Down Expand Up @@ -94,7 +93,7 @@ func Test_JavaScript_JS_Partial(t *testing.T) {
r.NoError(err)
defer os.RemoveAll(dir)

re := render.New(render.Options{
re := New(Options{
TemplatesBox: packr.NewBox(dir),
})

Expand All @@ -115,14 +114,34 @@ func Test_JavaScript_JS_Partial(t *testing.T) {
r.Equal("let a = 1;\nalert('hi!');", bb.String())
}

func Test_JavaScript_JS_Partial_Without_Extension(t *testing.T) {
r := require.New(t)

const testJS = "let a = 1;\n<%= partial(\"part\") %>"
const partJS = "alert('Hi <%= name %>!');"

err := withHTMLFile("test.js", testJS, func(e *Engine) {
err := withHTMLFile("_part.js", partJS, func(e *Engine) {
bb := &bytes.Buffer{}
renderer := e.JavaScript("test.js")
r.Equal("application/javascript", renderer.ContentType())
err := renderer.Render(bb, Data{"name": "Yonghwan"})
r.NoError(err)
r.Equal("let a = 1;\nalert('Hi Yonghwan!');", bb.String())
})
r.NoError(err)
})
r.NoError(err)
}

func Test_JavaScript_HTML_Partial(t *testing.T) {
r := require.New(t)

dir, err := ioutil.TempDir("", "")
r.NoError(err)
defer os.RemoveAll(dir)

re := render.New(render.Options{
re := New(Options{
TemplatesBox: packr.NewBox(dir),
})

Expand Down

0 comments on commit d5e1dd0

Please sign in to comment.